<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, minimal-ui" />
        
        <title>Dependent Viewer</title>
        
        <script src="../js/greyspots.js" type="text/javascript"></script>
        <script src="../js/d3.js" type="text/javascript"></script>
        <link href="../css/greyspots.css" type="text/css" rel="stylesheet" />
        <link href="../css/postage.css" type="text/css" rel="stylesheet" />
        
        <script src="resources/ws-get-functions.js" type="text/javascript"></script>
        <script src="resources/ws-tab-functions.js" type="text/javascript"></script>
        
        <script src="resources/ws-home.js" type="text/javascript"></script>
        
        <!-- right now these scripts are hard coded for postgres 9.2 -->
        <script src="resources/pg-9.2-tree-functions.js" type="text/javascript"></script>
        <script src="resources/pg-9.2-tree-queries.js" type="text/javascript"></script>
        <script src="resources/pg-9.2-autocomplete.js" type="text/javascript"></script>
        <script src="resources/pg-9.2-processes.js" type="text/javascript"></script>
        <script src="resources/pg-9.2-other.js" type="text/javascript"></script>
        
        <script>
            var _width, _height, color, force = null, svg, link, node, node_text, inspector_body, graph = {
                    nodes: [],
                    links: []
                }, mousedown_node, scripts = {}, depData = '', hidingOptions = {}, arrLine, arrColumn, trans = '0, 0', scale = '1', where_clause = 'TRUE', search_value = '', radius = 11.25;
            
            scripts.dependents = ml(function () {/*
WITH RECURSIVE dep_recursive AS (
    SELECT  pg_depend.refobjid AS objid,
            CASE    WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                                   THEN dpnder_pg_trigger_proc.oid
                    WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN'        THEN dpnder_pg_rewrite_class.oid
                    ELSE pg_depend.refobjid END AS effective_objid,
            CASE        WHEN pg_depend.refclassid::regclass = 'pg_type'::regclass                                               THEN dpnder_pg_namespace_type           .nspname || '.' ||  dpnder_pg_type.                 typname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_roles'::regclass                                              THEN                                                        dpnder_pg_roles.                rolname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_proc'::regclass                                               THEN dpnder_pg_namespace_proc           .nspname || '.' ||  dpnder_pg_proc.                 proname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_class'::regclass                                              THEN dpnder_pg_namespace_class          .nspname || '.' ||  dpnder_pg_class.                relname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_constraint'::regclass                                         THEN dpnder_pg_namespace_constraint     .nspname || '.' ||  dpnder_pg_constraint.           conname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_conversion'::regclass                                         THEN dpnder_pg_namespace_conversion     .nspname || '.' ||  dpnder_pg_conversion.           conname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_operator'::regclass                                           THEN dpnder_pg_namespace_operator       .nspname || '.' ||  dpnder_pg_operator.             oprname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_opfamily'::regclass                                           THEN dpnder_pg_namespace_opfamily       .nspname || '.' ||  dpnder_pg_opfamily.             opfname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_opclass'::regclass                                            THEN dpnder_pg_namespace_opclass        .nspname || '.' ||  dpnder_pg_opclass.              opcname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN' THEN dpnder_pg_namespace_rewrite_class  .nspname || '.' ||  dpnder_pg_rewrite_class.        relname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass                                            THEN                                                        dpnder_pg_rewrite.              rulename::text
                        WHEN pg_depend.refclassid::regclass = 'pg_language'::regclass                                           THEN                                                        dpnder_pg_language.             lanname::text
                        WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                               THEN dpnder_pg_namespace_trigger_proc   .nspname || '.' ||  dpnder_pg_trigger_proc.         proname::text || '(' || COALESCE(pg_get_function_arguments(dpnder_pg_trigger_proc.oid), '') || ')'
                        WHEN pg_depend.refclassid::regclass = 'pg_namespace'::regclass                                          THEN                                                        dpnder_pg_namespace.            nspname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_config'::regclass                                          THEN dpnder_pg_namespace_ts_config      .nspname || '.' ||  dpnder_pg_ts_config.            cfgname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_dict'::regclass                                            THEN dpnder_pg_namespace_ts_dict        .nspname || '.' ||  dpnder_pg_ts_dict.              dictname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_parser'::regclass                                          THEN dpnder_pg_namespace_ts_parser      .nspname || '.' ||  dpnder_pg_ts_parser.            prsname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_template'::regclass                                        THEN dpnder_pg_namespace_ts_template    .nspname || '.' ||  dpnder_pg_ts_template.          tmplname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_extension'::regclass                                          THEN dpnder_pg_namespace_extension      .nspname || '.' ||  dpnder_pg_extension.            extname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_data_wrapper'::regclass                               THEN                                                        dpnder_pg_foreign_data_wrapper. fdwname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_server'::regclass                                     THEN                                                        dpnder_pg_foreign_server.       srvname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_collation'::regclass                                          THEN dpnder_pg_namespace_collation      .nspname || '.' ||  dpnder_pg_collation.            collname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_cast'::regclass                                               THEN                                                        dpnder_pg_cast.                 oid::text
                        ELSE 'unknown' END AS dependent_name,
            CASE        WHEN pg_depend.refclassid::regclass = 'pg_type'::regclass                                               THEN 'TYPE'
                        WHEN pg_depend.refclassid::regclass = 'pg_roles'::regclass                                              THEN 'ROLE'
                        WHEN pg_depend.refclassid::regclass = 'pg_proc'::regclass                                               THEN 'FUNCTION'
                        WHEN pg_depend.refclassid::regclass = 'pg_class'::regclass                                              THEN
                                        	(CASE dpnder_pg_class.relkind   WHEN 'r' THEN 'TABLE'
                                        								    WHEN 'i' THEN 'INDEX'
                                        								    WHEN 'S' THEN 'SEQUENCE'
                                        								    WHEN 'v' THEN 'VIEW'
                                        								    WHEN 'c' THEN 'COMPOSITE TYPE'
                                        								    WHEN 't' THEN 'TOAST TABLE'
                                        								    WHEN 'f' THEN 'FOREIGN TABLE' END)
                        WHEN pg_depend.refclassid::regclass = 'pg_constraint'::regclass                                         THEN 'CONSTRAINT'
                        WHEN pg_depend.refclassid::regclass = 'pg_conversion'::regclass                                         THEN 'CONVERSION'
                        WHEN pg_depend.refclassid::regclass = 'pg_operator'::regclass                                           THEN 'OPERATOR'
                        WHEN pg_depend.refclassid::regclass = 'pg_opfamily'::regclass                                           THEN 'OPERATOR FAMILY'
                        WHEN pg_depend.refclassid::regclass = 'pg_opclass'::regclass                                            THEN 'OPERATOR CLASS'
                        WHEN pg_depend.refclassid::regclass = 'pg_language'::regclass                                           THEN 'LANGUAGE'
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN' THEN 'VIEW'
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass                                            THEN 'RULE'
                        WHEN pg_depend.refclassid::regclass = 'pg_trigger'::regclass                                            THEN 'TRIGGER'
                        WHEN pg_depend.refclassid::regclass = 'pg_namespace'::regclass                                          THEN 'SCHEMA'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_config'::regclass                                          THEN 'TEXT SEARCH CONFIG'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_dict'::regclass                                            THEN 'TEXT SEARCH DICTIONARY'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_parser'::regclass                                          THEN 'TEXT SEARCH PARSER'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_template'::regclass                                        THEN 'TEXT SEARCH TEMPLATE'
                        WHEN pg_depend.refclassid::regclass = 'pg_extension'::regclass                                          THEN 'EXTENSION'
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_data_wrapper'::regclass                               THEN 'FOREIGN DATA WRAPPER'
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_server'::regclass                                     THEN 'FOREIGN SERVER'
                        WHEN pg_depend.refclassid::regclass = 'pg_collation'::regclass                                          THEN 'COLLATION'
                        WHEN pg_depend.refclassid::regclass = 'pg_cast'::regclass                                               THEN 'CAST'
                        --WHEN pg_depend.refclassid::regclass = 'pg_tablespace'::regclass                                         THEN 'TABLESPACE'
                        ELSE 'unknown' END AS dependent_type,
            '0'::oid AS refobjid,
            '0'::oid AS effective_refobjid,
            '' AS depender_name,
            '' AS depender_type,
            ' '::text AS deptype
        FROM (
            SELECT *
                FROM pg_depend
                WHERE refobjid = '{{INTOID}}'::oid
        UNION ALL
            SELECT 'pg_class'::regclass::oid, objid, objsubid, 'pg_tablespace'::regclass::oid, refobjid, refobjsubid, deptype
                FROM (
                    SELECT  oid AS objid, 0 AS objsubid,
                            -- if tablespace is 0: replace with default tablespace
                            -- else: use the provided tablespace
                            (
                                CASE WHEN reltablespace = 0 THEN 
                                    COALESCE(
                                        (SELECT NULLIF(setting, '') FROM pg_settings WHERE name = 'default_tablespace')::text,
                                        (SELECT dattablespace FROM pg_database WHERE datname = CURRENT_DATABASE())::text
                                    )
                                ELSE
                                    reltablespace::text
                                END
                            )::oid AS refobjid,
                            0 AS refobjsubid, 'n' AS deptype
                        FROM pg_class
                ) pg_tablespace_depend
                WHERE pg_tablespace_depend.refobjid = '{{INTOID}}'
        ) pg_depend
        -- depender
        LEFT JOIN pg_roles                  dpnder_pg_roles                 ON dpnder_pg_roles.oid                  = pg_depend.refobjid::oid
        LEFT JOIN pg_type                   dpnder_pg_type                  ON dpnder_pg_type.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_proc                   dpnder_pg_proc                  ON dpnder_pg_proc.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_class                  dpnder_pg_class                 ON dpnder_pg_class.oid                  = pg_depend.refobjid::oid
        LEFT JOIN pg_attribute              dpnder_pg_attribute             ON dpnder_pg_attribute.attrelid         = pg_depend.refobjid::oid
                                                                           AND dpnder_pg_attribute.attnum           = pg_depend.refobjsubid
        LEFT JOIN pg_constraint             dpnder_pg_constraint            ON dpnder_pg_constraint.oid             = pg_depend.refobjid::oid
        LEFT JOIN pg_conversion             dpnder_pg_conversion            ON dpnder_pg_conversion.oid             = pg_depend.refobjid::oid
        LEFT JOIN pg_operator               dpnder_pg_operator              ON dpnder_pg_operator.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_opfamily               dpnder_pg_opfamily              ON dpnder_pg_opfamily.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_opclass                dpnder_pg_opclass               ON dpnder_pg_opclass.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_language               dpnder_pg_language              ON dpnder_pg_language.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_rewrite                dpnder_pg_rewrite               ON dpnder_pg_rewrite.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_class                  dpnder_pg_rewrite_class         ON dpnder_pg_rewrite_class.oid          = dpnder_pg_rewrite.ev_class::oid
        LEFT JOIN pg_trigger                dpnder_pg_trigger               ON dpnder_pg_trigger.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace             ON dpnder_pg_namespace.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_config              dpnder_pg_ts_config             ON dpnder_pg_ts_config.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_dict                dpnder_pg_ts_dict               ON dpnder_pg_ts_dict.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_parser              dpnder_pg_ts_parser             ON dpnder_pg_ts_parser.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_template            dpnder_pg_ts_template           ON dpnder_pg_ts_template.oid            = pg_depend.refobjid::oid
        LEFT JOIN pg_extension              dpnder_pg_extension             ON dpnder_pg_extension.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_foreign_data_wrapper   dpnder_pg_foreign_data_wrapper  ON dpnder_pg_foreign_data_wrapper.oid   = pg_depend.refobjid::oid
        LEFT JOIN pg_foreign_server         dpnder_pg_foreign_server        ON dpnder_pg_foreign_server.oid         = pg_depend.refobjid::oid
        LEFT JOIN pg_collation              dpnder_pg_collation             ON dpnder_pg_collation.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_cast                   dpnder_pg_cast                  ON dpnder_pg_cast.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_proc                   dpnder_pg_trigger_proc                    ON dpnder_pg_trigger_proc.oid                     = dpnder_pg_trigger.tgfoid
        LEFT JOIN pg_type                   dpnder_pg_proc_type                       ON dpnder_pg_proc_type.oid                        = dpnder_pg_proc.prorettype
        LEFT JOIN pg_namespace              dpnder_pg_namespace_type                  ON dpnder_pg_namespace_type.oid                   = dpnder_pg_type.                    typnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_proc                  ON dpnder_pg_namespace_proc.oid                   = dpnder_pg_proc.                    pronamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_class                 ON dpnder_pg_namespace_class.oid                  = dpnder_pg_class.                   relnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_constraint            ON dpnder_pg_namespace_constraint.oid             = dpnder_pg_constraint.              connamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_conversion            ON dpnder_pg_namespace_conversion.oid             = dpnder_pg_conversion.              connamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_operator              ON dpnder_pg_namespace_operator.oid               = dpnder_pg_operator.                oprnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_opfamily              ON dpnder_pg_namespace_opfamily.oid               = dpnder_pg_opfamily.                opfnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_opclass               ON dpnder_pg_namespace_opclass.oid                = dpnder_pg_opclass.                 opcnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_rewrite_class         ON dpnder_pg_namespace_rewrite_class.oid          = dpnder_pg_rewrite_class.           relnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_config             ON dpnder_pg_namespace_ts_config.oid              = dpnder_pg_ts_config.               cfgnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_dict               ON dpnder_pg_namespace_ts_dict.oid                = dpnder_pg_ts_dict.                 dictnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_parser             ON dpnder_pg_namespace_ts_parser.oid              = dpnder_pg_ts_parser.               prsnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_template           ON dpnder_pg_namespace_ts_template.oid            = dpnder_pg_ts_template.             tmplnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_extension             ON dpnder_pg_namespace_extension.oid              = dpnder_pg_extension.               extnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_collation             ON dpnder_pg_namespace_collation.oid              = dpnder_pg_collation.               collnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_trigger_proc          ON dpnder_pg_namespace_trigger_proc.oid           = dpnder_pg_trigger_proc.            pronamespace::oid
  UNION ALL
    SELECT  DISTINCT
            pg_depend.objid,
            CASE    WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                                   THEN dpndnt_pg_trigger_proc.oid
                    WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN'        THEN dpndnt_pg_rewrite_class.oid
                    ELSE pg_depend.objid END AS effective_objid,
            CASE        WHEN pg_depend.classid::regclass = 'pg_type'::regclass                                                  THEN dpndnt_pg_namespace_type           .nspname || '.' ||  dpndnt_pg_type.                 typname::text
                        WHEN pg_depend.classid::regclass = 'pg_roles'::regclass                                                 THEN                                                        dpndnt_pg_roles.                rolname::text
                        WHEN pg_depend.classid::regclass = 'pg_proc'::regclass                                                  THEN dpndnt_pg_namespace_proc           .nspname || '.' ||  dpndnt_pg_proc.                 proname::text || '(' || COALESCE(pg_get_function_arguments(dpndnt_pg_proc.oid), '') || ')'
                        WHEN pg_depend.classid::regclass = 'pg_class'::regclass                                                 THEN dpndnt_pg_namespace_class          .nspname || '.' ||  dpndnt_pg_class.                relname::text
                        WHEN pg_depend.classid::regclass = 'pg_constraint'::regclass                                            THEN dpndnt_pg_namespace_constraint     .nspname || '.' ||  dpndnt_pg_constraint.           conname::text
                        WHEN pg_depend.classid::regclass = 'pg_conversion'::regclass                                            THEN dpndnt_pg_namespace_conversion     .nspname || '.' ||  dpndnt_pg_conversion.           conname::text
                        WHEN pg_depend.classid::regclass = 'pg_operator'::regclass                                              THEN dpndnt_pg_namespace_operator       .nspname || '.' ||  dpndnt_pg_operator.             oprname::text
                        WHEN pg_depend.classid::regclass = 'pg_opfamily'::regclass                                              THEN dpndnt_pg_namespace_opfamily       .nspname || '.' ||  dpndnt_pg_opfamily.             opfname::text
                        WHEN pg_depend.classid::regclass = 'pg_opclass'::regclass                                               THEN dpndnt_pg_namespace_opclass        .nspname || '.' ||  dpndnt_pg_opclass.              opcname::text
                        WHEN pg_depend.classid::regclass = 'pg_language'::regclass                                              THEN                                                        dpndnt_pg_language.             lanname::text
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN'    THEN dpndnt_pg_namespace_rewrite_class  .nspname || '.' ||  dpndnt_pg_rewrite_class.        relname::text
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass                                               THEN                                                        dpndnt_pg_rewrite.              rulename::text
                        WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                               THEN dpndnt_pg_namespace_trigger_proc   .nspname || '.' ||  dpndnt_pg_trigger_proc.         proname::text || '(' || COALESCE(pg_get_function_arguments(dpndnt_pg_trigger_proc.oid), '') || ')'
                        WHEN pg_depend.classid::regclass = 'pg_namespace'::regclass                                             THEN                                                        dpndnt_pg_namespace.            nspname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_config'::regclass                                             THEN dpndnt_pg_namespace_ts_config      .nspname || '.' ||  dpndnt_pg_ts_config.            cfgname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_dict'::regclass                                               THEN dpndnt_pg_namespace_ts_dict        .nspname || '.' ||  dpndnt_pg_ts_dict.              dictname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_parser'::regclass                                             THEN dpndnt_pg_namespace_ts_parser      .nspname || '.' ||  dpndnt_pg_ts_parser.            prsname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_template'::regclass                                           THEN dpndnt_pg_namespace_ts_template    .nspname || '.' ||  dpndnt_pg_ts_template.          tmplname::text
                        WHEN pg_depend.classid::regclass = 'pg_extension'::regclass                                             THEN dpndnt_pg_namespace_extension      .nspname || '.' ||  dpndnt_pg_extension.            extname::text
                        WHEN pg_depend.classid::regclass = 'pg_foreign_data_wrapper'::regclass                                  THEN                                                        dpndnt_pg_foreign_data_wrapper. fdwname::text
                        WHEN pg_depend.classid::regclass = 'pg_foreign_server'::regclass                                        THEN                                                        dpndnt_pg_foreign_server.       srvname::text
                        WHEN pg_depend.classid::regclass = 'pg_collation'::regclass                                             THEN dpndnt_pg_namespace_collation      .nspname || '.' ||  dpndnt_pg_collation.            collname::text
                        WHEN pg_depend.classid::regclass = 'pg_cast'::regclass                                                  THEN                                                        dpndnt_pg_cast.                 oid::text
                        ELSE 'unknown' END AS dependent_name,
            CASE        WHEN pg_depend.classid::regclass = 'pg_type'::regclass                                                  THEN 'TYPE'
                        WHEN pg_depend.classid::regclass = 'pg_roles'::regclass                                                 THEN 'ROLE'
                        WHEN pg_depend.classid::regclass = 'pg_proc'::regclass                                                  THEN 'FUNCTION'
                        WHEN pg_depend.classid::regclass = 'pg_class'::regclass                                                 THEN
                                        	(CASE dpndnt_pg_class.relkind   WHEN 'r' THEN 'TABLE'
                                        								    WHEN 'i' THEN 'INDEX'
                                        								    WHEN 'S' THEN 'SEQUENCE'
                                        								    WHEN 'v' THEN 'VIEW'
                                        								    WHEN 'c' THEN 'COMPOSITE TYPE'
                                        								    WHEN 't' THEN 'TOAST TABLE'
                                        								    WHEN 'f' THEN 'FOREIGN TABLE' END)
                        WHEN pg_depend.classid::regclass = 'pg_constraint'::regclass                                            THEN 'CONSTRAINT'
                        WHEN pg_depend.classid::regclass = 'pg_conversion'::regclass                                            THEN 'CONVERSION'
                        WHEN pg_depend.classid::regclass = 'pg_operator'::regclass                                              THEN 'OPERATOR'
                        WHEN pg_depend.classid::regclass = 'pg_opfamily'::regclass                                              THEN 'OPERATOR FAMILY'
                        WHEN pg_depend.classid::regclass = 'pg_opclass'::regclass                                               THEN 'OPERATOR CLASS'
                        WHEN pg_depend.classid::regclass = 'pg_language'::regclass                                              THEN 'LANGUAGE'
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN'    THEN 'VIEW'
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass                                               THEN 'RULE'
                        WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                               THEN 'TRIGGER'
                        WHEN pg_depend.classid::regclass = 'pg_namespace'::regclass                                             THEN 'SCHEMA'
                        WHEN pg_depend.classid::regclass = 'pg_ts_config'::regclass                                             THEN 'TEXT SEARCH CONFIG'
                        WHEN pg_depend.classid::regclass = 'pg_ts_dict'::regclass                                               THEN 'TEXT SEARCH DICTIONARY'
                        WHEN pg_depend.classid::regclass = 'pg_ts_parser'::regclass                                             THEN 'TEXT SEARCH PARSER'
                        WHEN pg_depend.classid::regclass = 'pg_ts_template'::regclass                                           THEN 'TEXT SEARCH TEMPLATE'
                        WHEN pg_depend.classid::regclass = 'pg_extension'::regclass                                             THEN 'EXTENSION'
                        WHEN pg_depend.classid::regclass = 'pg_foreign_data_wrapper'::regclass                                  THEN 'FOREIGN DATA WRAPPER'
                        WHEN pg_depend.classid::regclass = 'pg_foreign_server'::regclass                                        THEN 'FOREIGN SERVER'
                        WHEN pg_depend.classid::regclass = 'pg_collation'::regclass                                             THEN 'COLLATION'
                        WHEN pg_depend.classid::regclass = 'pg_cast'::regclass                                                  THEN 'CAST'
                        ELSE 'unknown' END AS dependent_type,
            pg_depend.refobjid,
            CASE    WHEN pg_depend.refclassid::regclass = 'pg_trigger'::regclass                                                THEN dpnder_pg_trigger_proc.oid
                    WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN'     THEN dpnder_pg_rewrite_class.oid
                    ELSE pg_depend.refobjid END AS effective_refobjid,
            CASE        WHEN pg_depend.refclassid::regclass = 'pg_type'::regclass                                               THEN dpnder_pg_namespace_type           .nspname || '.' ||  dpnder_pg_type.                 typname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_roles'::regclass                                              THEN                                                        dpnder_pg_roles.                rolname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_proc'::regclass                                               THEN dpnder_pg_namespace_proc           .nspname || '.' ||  dpnder_pg_proc.                 proname::text || '(' || COALESCE(pg_get_function_arguments(dpnder_pg_proc.oid), '') || ')'
                        WHEN pg_depend.refclassid::regclass = 'pg_class'::regclass                                              THEN dpnder_pg_namespace_class          .nspname || '.' ||  dpnder_pg_class.                relname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_constraint'::regclass                                         THEN dpnder_pg_namespace_constraint     .nspname || '.' ||  dpnder_pg_constraint.           conname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_conversion'::regclass                                         THEN dpnder_pg_namespace_conversion     .nspname || '.' ||  dpnder_pg_conversion.           conname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_operator'::regclass                                           THEN dpnder_pg_namespace_operator       .nspname || '.' ||  dpnder_pg_operator.             oprname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_opfamily'::regclass                                           THEN dpnder_pg_namespace_opfamily       .nspname || '.' ||  dpnder_pg_opfamily.             opfname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_opclass'::regclass                                            THEN dpnder_pg_namespace_opclass        .nspname || '.' ||  dpnder_pg_opclass.              opcname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN' THEN dpnder_pg_namespace_rewrite_class  .nspname || '.' ||  dpnder_pg_rewrite_class.        relname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass                                            THEN                                                        dpnder_pg_rewrite.              rulename::text
                        WHEN pg_depend.refclassid::regclass = 'pg_language'::regclass                                           THEN                                                        dpnder_pg_language.             lanname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_trigger'::regclass                                            THEN dpnder_pg_namespace_trigger_proc   .nspname || '.' ||  dpnder_pg_trigger_proc.         proname::text || '(' || COALESCE(pg_get_function_arguments(dpnder_pg_trigger_proc.oid), '') || ')'
                        WHEN pg_depend.refclassid::regclass = 'pg_namespace'::regclass                                          THEN                                                        dpnder_pg_namespace.            nspname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_config'::regclass                                          THEN dpnder_pg_namespace_ts_config      .nspname || '.' ||  dpnder_pg_ts_config.            cfgname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_dict'::regclass                                            THEN dpnder_pg_namespace_ts_dict        .nspname || '.' ||  dpnder_pg_ts_dict.              dictname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_parser'::regclass                                          THEN dpnder_pg_namespace_ts_parser      .nspname || '.' ||  dpnder_pg_ts_parser.            prsname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_template'::regclass                                        THEN dpnder_pg_namespace_ts_template    .nspname || '.' ||  dpnder_pg_ts_template.          tmplname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_extension'::regclass                                          THEN dpnder_pg_namespace_extension      .nspname || '.' ||  dpnder_pg_extension.            extname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_data_wrapper'::regclass                               THEN                                                        dpnder_pg_foreign_data_wrapper. fdwname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_server'::regclass                                     THEN                                                        dpnder_pg_foreign_server.       srvname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_collation'::regclass                                          THEN dpnder_pg_namespace_collation      .nspname || '.' ||  dpnder_pg_collation.            collname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_cast'::regclass                                               THEN                                                        dpnder_pg_cast.                 oid::text
                        ELSE 'unknown' END AS depender_name,
            CASE        WHEN pg_depend.refclassid::regclass = 'pg_type'::regclass                                               THEN 'TYPE'
                        WHEN pg_depend.refclassid::regclass = 'pg_roles'::regclass                                              THEN 'ROLE'
                        WHEN pg_depend.refclassid::regclass = 'pg_proc'::regclass                                               THEN 'FUNCTION'
                        WHEN pg_depend.refclassid::regclass = 'pg_class'::regclass                                              THEN
                                        	(CASE dpnder_pg_class.relkind   WHEN 'r' THEN 'TABLE'
                                        								    WHEN 'i' THEN 'INDEX'
                                        								    WHEN 'S' THEN 'SEQUENCE'
                                        								    WHEN 'v' THEN 'VIEW'
                                        								    WHEN 'c' THEN 'COMPOSITE TYPE'
                                        								    WHEN 't' THEN 'TOAST TABLE'
                                        								    WHEN 'f' THEN 'FOREIGN TABLE' END)
                        WHEN pg_depend.refclassid::regclass = 'pg_constraint'::regclass                                         THEN 'CONSTRAINT'
                        WHEN pg_depend.refclassid::regclass = 'pg_conversion'::regclass                                         THEN 'CONVERSION'
                        WHEN pg_depend.refclassid::regclass = 'pg_operator'::regclass                                           THEN 'OPERATOR'
                        WHEN pg_depend.refclassid::regclass = 'pg_opfamily'::regclass                                           THEN 'OPERATOR FAMILY'
                        WHEN pg_depend.refclassid::regclass = 'pg_opclass'::regclass                                            THEN 'OPERATOR CLASS'
                        WHEN pg_depend.refclassid::regclass = 'pg_language'::regclass                                           THEN 'LANGUAGE'
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN' THEN 'VIEW'
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass                                            THEN 'RULE'
                        WHEN pg_depend.refclassid::regclass = 'pg_trigger'::regclass                                            THEN 'TRIGGER'
                        WHEN pg_depend.refclassid::regclass = 'pg_namespace'::regclass                                          THEN 'SCHEMA'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_config'::regclass                                          THEN 'TEXT SEARCH CONFIG'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_dict'::regclass                                            THEN 'TEXT SEARCH DICTIONARY'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_parser'::regclass                                          THEN 'TEXT SEARCH PARSER'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_template'::regclass                                        THEN 'TEXT SEARCH TEMPLATE'
                        WHEN pg_depend.refclassid::regclass = 'pg_extension'::regclass                                          THEN 'EXTENSION'
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_data_wrapper'::regclass                               THEN 'FOREIGN DATA WRAPPER'
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_server'::regclass                                     THEN 'FOREIGN SERVER'
                        WHEN pg_depend.refclassid::regclass = 'pg_collation'::regclass                                          THEN 'COLLATION'
                        WHEN pg_depend.refclassid::regclass = 'pg_cast'::regclass                                               THEN 'CAST'
                        ELSE 'unknown' END AS depender_type,
            (CASE   WHEN pg_depend.deptype = 'p'    THEN 'Pinned'
                    WHEN pg_depend.deptype = 'i'    THEN 'Internal'
                    WHEN pg_depend.deptype = 'a'    THEN 'Automatic'
                    WHEN pg_depend.deptype = 'n'    THEN 'Normal'
                    WHEN pg_depend.deptype = 'o_sh' THEN 'Owner'
                    WHEN pg_depend.deptype = 'a_sh' THEN 'ACL'
                    WHEN pg_depend.deptype = 'p_sh' THEN 'Pinned' END)::text AS deptype
        FROM (
            SELECT *
                FROM pg_depend
        UNION ALL
            SELECT 'pg_class'::regclass::oid, objid, objsubid, 'pg_tablespace'::regclass::oid, refobjid, refobjsubid, deptype
                FROM (
                    SELECT  oid AS objid, 0 AS objsubid,
                            -- if tablespace is 0: replace with default tablespace
                            -- else: use the provided tablespace
                            (
                                CASE WHEN reltablespace = 0 THEN 
                                    COALESCE(
                                        (SELECT NULLIF(setting, '') FROM pg_settings WHERE name = 'default_tablespace')::text,
                                        (SELECT dattablespace FROM pg_database WHERE datname = CURRENT_DATABASE())::text
                                    )
                                ELSE
                                    reltablespace::text
                                END
                            )::oid AS refobjid,
                            0 AS refobjsubid, 'n' AS deptype
                        FROM pg_class
                ) pg_tablespace_depend
                WHERE pg_tablespace_depend.refobjid = '{{INTOID}}'
        ) pg_depend
        -- depender
        LEFT JOIN pg_roles                  dpnder_pg_roles                 ON dpnder_pg_roles.oid                  = pg_depend.refobjid::oid
        LEFT JOIN pg_type                   dpnder_pg_type                  ON dpnder_pg_type.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_proc                   dpnder_pg_proc                  ON dpnder_pg_proc.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_class                  dpnder_pg_class                 ON dpnder_pg_class.oid                  = pg_depend.refobjid::oid
        LEFT JOIN pg_attribute              dpnder_pg_attribute             ON dpnder_pg_attribute.attrelid         = pg_depend.refobjid::oid
                                                                           AND dpnder_pg_attribute.attnum           = pg_depend.refobjsubid
        LEFT JOIN pg_constraint             dpnder_pg_constraint            ON dpnder_pg_constraint.oid             = pg_depend.refobjid::oid
        LEFT JOIN pg_conversion             dpnder_pg_conversion            ON dpnder_pg_conversion.oid             = pg_depend.refobjid::oid
        LEFT JOIN pg_operator               dpnder_pg_operator              ON dpnder_pg_operator.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_opfamily               dpnder_pg_opfamily              ON dpnder_pg_opfamily.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_opclass                dpnder_pg_opclass               ON dpnder_pg_opclass.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_language               dpnder_pg_language              ON dpnder_pg_language.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_rewrite                dpnder_pg_rewrite               ON dpnder_pg_rewrite.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_class                  dpnder_pg_rewrite_class         ON dpnder_pg_rewrite_class.oid          = dpnder_pg_rewrite.ev_class::oid
        LEFT JOIN pg_trigger                dpnder_pg_trigger               ON dpnder_pg_trigger.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace             ON dpnder_pg_namespace.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_config              dpnder_pg_ts_config             ON dpnder_pg_ts_config.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_dict                dpnder_pg_ts_dict               ON dpnder_pg_ts_dict.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_parser              dpnder_pg_ts_parser             ON dpnder_pg_ts_parser.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_template            dpnder_pg_ts_template           ON dpnder_pg_ts_template.oid            = pg_depend.refobjid::oid
        LEFT JOIN pg_extension              dpnder_pg_extension             ON dpnder_pg_extension.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_foreign_data_wrapper   dpnder_pg_foreign_data_wrapper  ON dpnder_pg_foreign_data_wrapper.oid   = pg_depend.refobjid::oid
        LEFT JOIN pg_foreign_server         dpnder_pg_foreign_server        ON dpnder_pg_foreign_server.oid         = pg_depend.refobjid::oid
        LEFT JOIN pg_collation              dpnder_pg_collation             ON dpnder_pg_collation.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_cast                   dpnder_pg_cast                  ON dpnder_pg_cast.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_proc                   dpnder_pg_trigger_proc                    ON dpnder_pg_trigger_proc.oid                     = dpnder_pg_trigger.tgfoid
        LEFT JOIN pg_type                   dpnder_pg_proc_type                       ON dpnder_pg_proc_type.oid                        = dpnder_pg_proc.prorettype
        LEFT JOIN pg_namespace              dpnder_pg_namespace_type                  ON dpnder_pg_namespace_type.oid                   = dpnder_pg_type.                    typnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_proc                  ON dpnder_pg_namespace_proc.oid                   = dpnder_pg_proc.                    pronamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_class                 ON dpnder_pg_namespace_class.oid                  = dpnder_pg_class.                   relnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_constraint            ON dpnder_pg_namespace_constraint.oid             = dpnder_pg_constraint.              connamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_conversion            ON dpnder_pg_namespace_conversion.oid             = dpnder_pg_conversion.              connamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_operator              ON dpnder_pg_namespace_operator.oid               = dpnder_pg_operator.                oprnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_opfamily              ON dpnder_pg_namespace_opfamily.oid               = dpnder_pg_opfamily.                opfnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_opclass               ON dpnder_pg_namespace_opclass.oid                = dpnder_pg_opclass.                 opcnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_rewrite_class         ON dpnder_pg_namespace_rewrite_class.oid          = dpnder_pg_rewrite_class.           relnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_config             ON dpnder_pg_namespace_ts_config.oid              = dpnder_pg_ts_config.               cfgnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_dict               ON dpnder_pg_namespace_ts_dict.oid                = dpnder_pg_ts_dict.                 dictnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_parser             ON dpnder_pg_namespace_ts_parser.oid              = dpnder_pg_ts_parser.               prsnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_template           ON dpnder_pg_namespace_ts_template.oid            = dpnder_pg_ts_template.             tmplnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_extension             ON dpnder_pg_namespace_extension.oid              = dpnder_pg_extension.               extnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_collation             ON dpnder_pg_namespace_collation.oid              = dpnder_pg_collation.               collnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_trigger_proc          ON dpnder_pg_namespace_trigger_proc.oid           = dpnder_pg_trigger_proc.            pronamespace::oid
        -- dependents
        LEFT JOIN pg_roles                  dpndnt_pg_roles                 ON dpndnt_pg_roles.oid                  = pg_depend.objid::oid
        LEFT JOIN pg_type                   dpndnt_pg_type                  ON dpndnt_pg_type.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_proc                   dpndnt_pg_proc                  ON dpndnt_pg_proc.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_class                  dpndnt_pg_class                 ON dpndnt_pg_class.oid                  = pg_depend.objid::oid
        LEFT JOIN pg_attribute              dpndnt_pg_attribute             ON dpndnt_pg_attribute.attrelid         = pg_depend.objid::oid
                                                                           AND dpndnt_pg_attribute.attnum           = pg_depend.objsubid
        LEFT JOIN pg_constraint             dpndnt_pg_constraint            ON dpndnt_pg_constraint.oid             = pg_depend.objid::oid
        LEFT JOIN pg_conversion             dpndnt_pg_conversion            ON dpndnt_pg_conversion.oid             = pg_depend.objid::oid
        LEFT JOIN pg_operator               dpndnt_pg_operator              ON dpndnt_pg_operator.oid               = pg_depend.objid::oid
        LEFT JOIN pg_opfamily               dpndnt_pg_opfamily              ON dpndnt_pg_opfamily.oid               = pg_depend.objid::oid
        LEFT JOIN pg_opclass                dpndnt_pg_opclass               ON dpndnt_pg_opclass.oid                = pg_depend.objid::oid
        LEFT JOIN pg_language               dpndnt_pg_language              ON dpndnt_pg_language.oid               = pg_depend.objid::oid
        LEFT JOIN pg_rewrite                dpndnt_pg_rewrite               ON dpndnt_pg_rewrite.oid                = pg_depend.objid::oid
        LEFT JOIN pg_class                  dpndnt_pg_rewrite_class         ON dpndnt_pg_rewrite_class.oid          = dpndnt_pg_rewrite.ev_class::oid
        LEFT JOIN pg_trigger                dpndnt_pg_trigger               ON dpndnt_pg_trigger.oid                = pg_depend.objid::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace             ON dpndnt_pg_namespace.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_config              dpndnt_pg_ts_config             ON dpndnt_pg_ts_config.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_dict                dpndnt_pg_ts_dict               ON dpndnt_pg_ts_dict.oid                = pg_depend.objid::oid
        LEFT JOIN pg_ts_parser              dpndnt_pg_ts_parser             ON dpndnt_pg_ts_parser.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_template            dpndnt_pg_ts_template           ON dpndnt_pg_ts_template.oid            = pg_depend.objid::oid
        LEFT JOIN pg_extension              dpndnt_pg_extension             ON dpndnt_pg_extension.oid              = pg_depend.objid::oid
        LEFT JOIN pg_foreign_data_wrapper   dpndnt_pg_foreign_data_wrapper  ON dpndnt_pg_foreign_data_wrapper.oid   = pg_depend.objid::oid
        LEFT JOIN pg_foreign_server         dpndnt_pg_foreign_server        ON dpndnt_pg_foreign_server.oid         = pg_depend.objid::oid
        LEFT JOIN pg_collation              dpndnt_pg_collation             ON dpndnt_pg_collation.oid              = pg_depend.objid::oid
        LEFT JOIN pg_cast                   dpndnt_pg_cast                  ON dpndnt_pg_cast.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_proc                   dpndnt_pg_trigger_proc                    ON dpndnt_pg_trigger_proc.oid                     = dpndnt_pg_trigger.tgfoid
        LEFT JOIN pg_type                   dpndnt_pg_proc_type                       ON dpndnt_pg_proc_type.oid                        = dpndnt_pg_proc.prorettype
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_type                  ON dpndnt_pg_namespace_type.oid                   = dpndnt_pg_type.                    typnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_proc                  ON dpndnt_pg_namespace_proc.oid                   = dpndnt_pg_proc.                    pronamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_class                 ON dpndnt_pg_namespace_class.oid                  = dpndnt_pg_class.                   relnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_constraint            ON dpndnt_pg_namespace_constraint.oid             = dpndnt_pg_constraint.              connamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_conversion            ON dpndnt_pg_namespace_conversion.oid             = dpndnt_pg_conversion.              connamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_operator              ON dpndnt_pg_namespace_operator.oid               = dpndnt_pg_operator.                oprnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_opfamily              ON dpndnt_pg_namespace_opfamily.oid               = dpndnt_pg_opfamily.                opfnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_opclass               ON dpndnt_pg_namespace_opclass.oid                = dpndnt_pg_opclass.                 opcnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_rewrite_class         ON dpndnt_pg_namespace_rewrite_class.oid          = dpndnt_pg_rewrite_class.           relnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_config             ON dpndnt_pg_namespace_ts_config.oid              = dpndnt_pg_ts_config.               cfgnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_dict               ON dpndnt_pg_namespace_ts_dict.oid                = dpndnt_pg_ts_dict.                 dictnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_parser             ON dpndnt_pg_namespace_ts_parser.oid              = dpndnt_pg_ts_parser.               prsnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_template           ON dpndnt_pg_namespace_ts_template.oid            = dpndnt_pg_ts_template.             tmplnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_extension             ON dpndnt_pg_namespace_extension.oid              = dpndnt_pg_extension.               extnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_collation             ON dpndnt_pg_namespace_collation.oid              = dpndnt_pg_collation.               collnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_trigger_proc          ON dpndnt_pg_namespace_trigger_proc.oid           = dpndnt_pg_trigger_proc.            pronamespace::oid
        --recurse
        JOIN dep_recursive dep_recursive ON dep_recursive.objid::oid = pg_depend.refobjid::oid
        WHERE pg_depend.objid != 0
          AND pg_depend.refobjid != 0
          AND pg_depend.deptype != 'i'
          AND pg_depend.classid::regclass != 'pg_default_acl'::regclass
          AND pg_depend.classid::regclass != 'pg_attrdef'::regclass
          AND pg_depend.classid::regclass != 'pg_am'::regclass
          AND (dpndnt_pg_proc_type.typname != 'trigger' OR dpndnt_pg_proc_type.typname IS NULL)
          AND (dpnder_pg_proc_type.typname != 'trigger' OR dpnder_pg_proc_type.typname IS NULL)
          AND pg_depend.objid != '{{INTOID}}'::oid
)
SELECT *
    FROM dep_recursive
    WHERE dependent_name <> '' AND {{WHERE}}
            */});
            
            scripts.dependencies = ml(function () {/*
WITH RECURSIVE dep_recursive AS (
    SELECT  '0'::oid AS objid,
            '0'::oid AS effective_objid,
            '' AS dependent_name,
            '' AS dependent_type,
            pg_depend.objid AS refobjid,
            CASE    WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                                THEN dpndnt_pg_trigger_proc.oid
                    WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN'     THEN dpndnt_pg_rewrite_class.oid
                    ELSE pg_depend.objid END AS effective_refobjid,
            CASE        WHEN pg_depend.classid::regclass = 'pg_type'::regclass                                               THEN dpndnt_pg_namespace_type           .nspname || '.' ||  dpndnt_pg_type.                 typname::text
                        WHEN pg_depend.classid::regclass = 'pg_roles'::regclass                                              THEN                                                        dpndnt_pg_roles.                rolname::text
                        WHEN pg_depend.classid::regclass = 'pg_proc'::regclass                                               THEN dpndnt_pg_namespace_proc           .nspname || '.' ||  dpndnt_pg_proc.                 proname::text || '(' || COALESCE(pg_get_function_arguments(dpndnt_pg_proc.oid), '') || ')'
                        WHEN pg_depend.classid::regclass = 'pg_class'::regclass                                              THEN dpndnt_pg_namespace_class          .nspname || '.' ||  dpndnt_pg_class.                relname::text
                        WHEN pg_depend.classid::regclass = 'pg_constraint'::regclass                                         THEN dpndnt_pg_namespace_constraint     .nspname || '.' ||  dpndnt_pg_constraint.           conname::text
                        WHEN pg_depend.classid::regclass = 'pg_conversion'::regclass                                         THEN dpndnt_pg_namespace_conversion     .nspname || '.' ||  dpndnt_pg_conversion.           conname::text
                        WHEN pg_depend.classid::regclass = 'pg_operator'::regclass                                           THEN dpndnt_pg_namespace_operator       .nspname || '.' ||  dpndnt_pg_operator.             oprname::text
                        WHEN pg_depend.classid::regclass = 'pg_opfamily'::regclass                                           THEN dpndnt_pg_namespace_opfamily       .nspname || '.' ||  dpndnt_pg_opfamily.             opfname::text
                        WHEN pg_depend.classid::regclass = 'pg_opclass'::regclass                                            THEN dpndnt_pg_namespace_opclass        .nspname || '.' ||  dpndnt_pg_opclass.              opcname::text
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN' THEN dpndnt_pg_namespace_rewrite_class  .nspname || '.' ||  dpndnt_pg_rewrite_class.        relname::text
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass                                            THEN                                                        dpndnt_pg_rewrite.              rulename::text
                        WHEN pg_depend.classid::regclass = 'pg_language'::regclass                                           THEN                                                        dpndnt_pg_language.             lanname::text
                        WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                            THEN dpndnt_pg_namespace_trigger_proc   .nspname || '.' ||  dpndnt_pg_trigger_proc.         proname::text || '(' || COALESCE(pg_get_function_arguments(dpndnt_pg_trigger_proc.oid), '') || ')'
                        WHEN pg_depend.classid::regclass = 'pg_namespace'::regclass                                          THEN                                                        dpndnt_pg_namespace.            nspname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_config'::regclass                                          THEN dpndnt_pg_namespace_ts_config      .nspname || '.' ||  dpndnt_pg_ts_config.            cfgname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_dict'::regclass                                            THEN dpndnt_pg_namespace_ts_dict        .nspname || '.' ||  dpndnt_pg_ts_dict.              dictname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_parser'::regclass                                          THEN dpndnt_pg_namespace_ts_parser      .nspname || '.' ||  dpndnt_pg_ts_parser.            prsname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_template'::regclass                                        THEN dpndnt_pg_namespace_ts_template    .nspname || '.' ||  dpndnt_pg_ts_template.          tmplname::text
                        WHEN pg_depend.classid::regclass = 'pg_extension'::regclass                                          THEN dpndnt_pg_namespace_extension      .nspname || '.' ||  dpndnt_pg_extension.            extname::text
                        WHEN pg_depend.classid::regclass = 'pg_foreign_data_wrapper'::regclass                               THEN                                                        dpndnt_pg_foreign_data_wrapper. fdwname::text
                        WHEN pg_depend.classid::regclass = 'pg_foreign_server'::regclass                                     THEN                                                        dpndnt_pg_foreign_server.       srvname::text
                        WHEN pg_depend.classid::regclass = 'pg_collation'::regclass                                          THEN dpndnt_pg_namespace_collation      .nspname || '.' ||  dpndnt_pg_collation.            collname::text
                        WHEN pg_depend.classid::regclass = 'pg_cast'::regclass                                               THEN                                                        dpndnt_pg_cast.                 oid::text
                        ELSE 'unknown' END AS depender_name,
            CASE        WHEN pg_depend.classid::regclass = 'pg_type'::regclass                                               THEN 'TYPE'
                        WHEN pg_depend.classid::regclass = 'pg_roles'::regclass                                              THEN 'ROLE'
                        WHEN pg_depend.classid::regclass = 'pg_proc'::regclass                                               THEN 'FUNCTION'
                        WHEN pg_depend.classid::regclass = 'pg_class'::regclass                                              THEN
                                        	(CASE dpndnt_pg_class.relkind   WHEN 'r' THEN 'TABLE'
                                        								    WHEN 'i' THEN 'INDEX'
                                        								    WHEN 'S' THEN 'SEQUENCE'
                                        								    WHEN 'v' THEN 'VIEW'
                                        								    WHEN 'c' THEN 'COMPOSITE TYPE'
                                        								    WHEN 't' THEN 'TOAST TABLE'
                                        								    WHEN 'f' THEN 'FOREIGN TABLE' END)
                        WHEN pg_depend.classid::regclass = 'pg_constraint'::regclass                                         THEN 'CONSTRAINT'
                        WHEN pg_depend.classid::regclass = 'pg_conversion'::regclass                                         THEN 'CONVERSION'
                        WHEN pg_depend.classid::regclass = 'pg_operator'::regclass                                           THEN 'OPERATOR'
                        WHEN pg_depend.classid::regclass = 'pg_opfamily'::regclass                                           THEN 'OPERATOR FAMILY'
                        WHEN pg_depend.classid::regclass = 'pg_opclass'::regclass                                            THEN 'OPERATOR CLASS'
                        WHEN pg_depend.classid::regclass = 'pg_language'::regclass                                           THEN 'LANGUAGE'
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN' THEN 'VIEW'
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass                                            THEN 'RULE'
                        WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                            THEN 'TRIGGER'
                        WHEN pg_depend.classid::regclass = 'pg_namespace'::regclass                                          THEN 'SCHEMA'
                        WHEN pg_depend.classid::regclass = 'pg_ts_config'::regclass                                          THEN 'TEXT SEARCH CONFIG'
                        WHEN pg_depend.classid::regclass = 'pg_ts_dict'::regclass                                            THEN 'TEXT SEARCH DICTIONARY'
                        WHEN pg_depend.classid::regclass = 'pg_ts_parser'::regclass                                          THEN 'TEXT SEARCH PARSER'
                        WHEN pg_depend.classid::regclass = 'pg_ts_template'::regclass                                        THEN 'TEXT SEARCH TEMPLATE'
                        WHEN pg_depend.classid::regclass = 'pg_extension'::regclass                                          THEN 'EXTENSION'
                        WHEN pg_depend.classid::regclass = 'pg_foreign_data_wrapper'::regclass                               THEN 'FOREIGN DATA WRAPPER'
                        WHEN pg_depend.classid::regclass = 'pg_foreign_server'::regclass                                     THEN 'FOREIGN SERVER'
                        WHEN pg_depend.classid::regclass = 'pg_collation'::regclass                                          THEN 'COLLATION'
                        WHEN pg_depend.classid::regclass = 'pg_cast'::regclass                                               THEN 'CAST'
                        ELSE 'unknown' END AS depender_type,
            ' '::text AS deptype
        FROM (
            SELECT *
                FROM pg_depend
                WHERE objid = '{{INTOID}}'::oid
                LIMIT 1
        ) pg_depend
        -- dependents
        LEFT JOIN pg_roles                  dpndnt_pg_roles                 ON dpndnt_pg_roles.oid                  = pg_depend.objid::oid
        LEFT JOIN pg_type                   dpndnt_pg_type                  ON dpndnt_pg_type.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_proc                   dpndnt_pg_proc                  ON dpndnt_pg_proc.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_class                  dpndnt_pg_class                 ON dpndnt_pg_class.oid                  = pg_depend.objid::oid
        LEFT JOIN pg_attribute              dpndnt_pg_attribute             ON dpndnt_pg_attribute.attrelid         = pg_depend.objid::oid
                                                                           AND dpndnt_pg_attribute.attnum           = pg_depend.objsubid
        LEFT JOIN pg_constraint             dpndnt_pg_constraint            ON dpndnt_pg_constraint.oid             = pg_depend.objid::oid
        LEFT JOIN pg_conversion             dpndnt_pg_conversion            ON dpndnt_pg_conversion.oid             = pg_depend.objid::oid
        LEFT JOIN pg_operator               dpndnt_pg_operator              ON dpndnt_pg_operator.oid               = pg_depend.objid::oid
        LEFT JOIN pg_opfamily               dpndnt_pg_opfamily              ON dpndnt_pg_opfamily.oid               = pg_depend.objid::oid
        LEFT JOIN pg_opclass                dpndnt_pg_opclass               ON dpndnt_pg_opclass.oid                = pg_depend.objid::oid
        LEFT JOIN pg_language               dpndnt_pg_language              ON dpndnt_pg_language.oid               = pg_depend.objid::oid
        LEFT JOIN pg_rewrite                dpndnt_pg_rewrite               ON dpndnt_pg_rewrite.oid                = pg_depend.objid::oid
        LEFT JOIN pg_class                  dpndnt_pg_rewrite_class         ON dpndnt_pg_rewrite_class.oid          = dpndnt_pg_rewrite.ev_class::oid
        LEFT JOIN pg_trigger                dpndnt_pg_trigger               ON dpndnt_pg_trigger.oid                = pg_depend.objid::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace             ON dpndnt_pg_namespace.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_config              dpndnt_pg_ts_config             ON dpndnt_pg_ts_config.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_dict                dpndnt_pg_ts_dict               ON dpndnt_pg_ts_dict.oid                = pg_depend.objid::oid
        LEFT JOIN pg_ts_parser              dpndnt_pg_ts_parser             ON dpndnt_pg_ts_parser.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_template            dpndnt_pg_ts_template           ON dpndnt_pg_ts_template.oid            = pg_depend.objid::oid
        LEFT JOIN pg_extension              dpndnt_pg_extension             ON dpndnt_pg_extension.oid              = pg_depend.objid::oid
        LEFT JOIN pg_foreign_data_wrapper   dpndnt_pg_foreign_data_wrapper  ON dpndnt_pg_foreign_data_wrapper.oid   = pg_depend.objid::oid
        LEFT JOIN pg_foreign_server         dpndnt_pg_foreign_server        ON dpndnt_pg_foreign_server.oid         = pg_depend.objid::oid
        LEFT JOIN pg_collation              dpndnt_pg_collation             ON dpndnt_pg_collation.oid              = pg_depend.objid::oid
        LEFT JOIN pg_cast                   dpndnt_pg_cast                  ON dpndnt_pg_cast.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_proc                   dpndnt_pg_trigger_proc                    ON dpndnt_pg_trigger_proc.oid                     = dpndnt_pg_trigger.tgfoid
        LEFT JOIN pg_type                   dpndnt_pg_proc_type                       ON dpndnt_pg_proc_type.oid                        = dpndnt_pg_proc.prorettype
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_type                  ON dpndnt_pg_namespace_type.oid                   = dpndnt_pg_type.                    typnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_proc                  ON dpndnt_pg_namespace_proc.oid                   = dpndnt_pg_proc.                    pronamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_class                 ON dpndnt_pg_namespace_class.oid                  = dpndnt_pg_class.                   relnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_constraint            ON dpndnt_pg_namespace_constraint.oid             = dpndnt_pg_constraint.              connamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_conversion            ON dpndnt_pg_namespace_conversion.oid             = dpndnt_pg_conversion.              connamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_operator              ON dpndnt_pg_namespace_operator.oid               = dpndnt_pg_operator.                oprnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_opfamily              ON dpndnt_pg_namespace_opfamily.oid               = dpndnt_pg_opfamily.                opfnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_opclass               ON dpndnt_pg_namespace_opclass.oid                = dpndnt_pg_opclass.                 opcnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_rewrite_class         ON dpndnt_pg_namespace_rewrite_class.oid          = dpndnt_pg_rewrite_class.           relnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_config             ON dpndnt_pg_namespace_ts_config.oid              = dpndnt_pg_ts_config.               cfgnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_dict               ON dpndnt_pg_namespace_ts_dict.oid                = dpndnt_pg_ts_dict.                 dictnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_parser             ON dpndnt_pg_namespace_ts_parser.oid              = dpndnt_pg_ts_parser.               prsnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_template           ON dpndnt_pg_namespace_ts_template.oid            = dpndnt_pg_ts_template.             tmplnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_extension             ON dpndnt_pg_namespace_extension.oid              = dpndnt_pg_extension.               extnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_collation             ON dpndnt_pg_namespace_collation.oid              = dpndnt_pg_collation.               collnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_trigger_proc          ON dpndnt_pg_namespace_trigger_proc.oid           = dpndnt_pg_trigger_proc.            pronamespace::oid
  UNION ALL
    SELECT  DISTINCT
            pg_depend.objid,
            CASE    WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                                   THEN dpndnt_pg_trigger_proc.oid
                    WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN'        THEN dpndnt_pg_rewrite_class.oid
                    ELSE pg_depend.objid END AS effective_objid,
            CASE        WHEN pg_depend.classid::regclass = 'pg_type'::regclass                                                  THEN dpndnt_pg_namespace_type           .nspname || '.' ||  dpndnt_pg_type.                 typname::text
                        WHEN pg_depend.classid::regclass = 'pg_roles'::regclass                                                 THEN                                                        dpndnt_pg_roles.                rolname::text
                        WHEN pg_depend.classid::regclass = 'pg_proc'::regclass                                                  THEN dpndnt_pg_namespace_proc           .nspname || '.' ||  dpndnt_pg_proc.                 proname::text || '(' || COALESCE(pg_get_function_arguments(dpndnt_pg_proc.oid), '') || ')'
                        WHEN pg_depend.classid::regclass = 'pg_class'::regclass                                                 THEN dpndnt_pg_namespace_class          .nspname || '.' ||  dpndnt_pg_class.                relname::text
                        WHEN pg_depend.classid::regclass = 'pg_constraint'::regclass                                            THEN dpndnt_pg_namespace_constraint     .nspname || '.' ||  dpndnt_pg_constraint.           conname::text
                        WHEN pg_depend.classid::regclass = 'pg_conversion'::regclass                                            THEN dpndnt_pg_namespace_conversion     .nspname || '.' ||  dpndnt_pg_conversion.           conname::text
                        WHEN pg_depend.classid::regclass = 'pg_operator'::regclass                                              THEN dpndnt_pg_namespace_operator       .nspname || '.' ||  dpndnt_pg_operator.             oprname::text
                        WHEN pg_depend.classid::regclass = 'pg_opfamily'::regclass                                              THEN dpndnt_pg_namespace_opfamily       .nspname || '.' ||  dpndnt_pg_opfamily.             opfname::text
                        WHEN pg_depend.classid::regclass = 'pg_opclass'::regclass                                               THEN dpndnt_pg_namespace_opclass        .nspname || '.' ||  dpndnt_pg_opclass.              opcname::text
                        WHEN pg_depend.classid::regclass = 'pg_language'::regclass                                              THEN                                                        dpndnt_pg_language.             lanname::text
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN'    THEN dpndnt_pg_namespace_rewrite_class  .nspname || '.' ||  dpndnt_pg_rewrite_class.        relname::text
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass                                               THEN                                                        dpndnt_pg_rewrite.              rulename::text
                        WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                               THEN dpndnt_pg_namespace_trigger_proc   .nspname || '.' ||  dpndnt_pg_trigger_proc.         proname::text || '(' || COALESCE(pg_get_function_arguments(dpndnt_pg_trigger_proc.oid), '') || ')'
                        WHEN pg_depend.classid::regclass = 'pg_namespace'::regclass                                             THEN                                                        dpndnt_pg_namespace.            nspname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_config'::regclass                                             THEN dpndnt_pg_namespace_ts_config      .nspname || '.' ||  dpndnt_pg_ts_config.            cfgname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_dict'::regclass                                               THEN dpndnt_pg_namespace_ts_dict        .nspname || '.' ||  dpndnt_pg_ts_dict.              dictname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_parser'::regclass                                             THEN dpndnt_pg_namespace_ts_parser      .nspname || '.' ||  dpndnt_pg_ts_parser.            prsname::text
                        WHEN pg_depend.classid::regclass = 'pg_ts_template'::regclass                                           THEN dpndnt_pg_namespace_ts_template    .nspname || '.' ||  dpndnt_pg_ts_template.          tmplname::text
                        WHEN pg_depend.classid::regclass = 'pg_extension'::regclass                                             THEN dpndnt_pg_namespace_extension      .nspname || '.' ||  dpndnt_pg_extension.            extname::text
                        WHEN pg_depend.classid::regclass = 'pg_foreign_data_wrapper'::regclass                                  THEN                                                        dpndnt_pg_foreign_data_wrapper. fdwname::text
                        WHEN pg_depend.classid::regclass = 'pg_foreign_server'::regclass                                        THEN                                                        dpndnt_pg_foreign_server.       srvname::text
                        WHEN pg_depend.classid::regclass = 'pg_collation'::regclass                                             THEN dpndnt_pg_namespace_collation      .nspname || '.' ||  dpndnt_pg_collation.            collname::text
                        WHEN pg_depend.classid::regclass = 'pg_cast'::regclass                                                  THEN                                                        dpndnt_pg_cast.                 oid::text
                        ELSE 'unknown' END AS dependent_name,
            CASE        WHEN pg_depend.classid::regclass = 'pg_type'::regclass                                                  THEN 'TYPE'
                        WHEN pg_depend.classid::regclass = 'pg_roles'::regclass                                                 THEN 'ROLE'
                        WHEN pg_depend.classid::regclass = 'pg_proc'::regclass                                                  THEN 'FUNCTION'
                        WHEN pg_depend.classid::regclass = 'pg_class'::regclass                                                 THEN
                                        	(CASE dpndnt_pg_class.relkind   WHEN 'r' THEN 'TABLE'
                                        								    WHEN 'i' THEN 'INDEX'
                                        								    WHEN 'S' THEN 'SEQUENCE'
                                        								    WHEN 'v' THEN 'VIEW'
                                        								    WHEN 'c' THEN 'COMPOSITE TYPE'
                                        								    WHEN 't' THEN 'TOAST TABLE'
                                        								    WHEN 'f' THEN 'FOREIGN TABLE' END)
                        WHEN pg_depend.classid::regclass = 'pg_constraint'::regclass                                            THEN 'CONSTRAINT'
                        WHEN pg_depend.classid::regclass = 'pg_conversion'::regclass                                            THEN 'CONVERSION'
                        WHEN pg_depend.classid::regclass = 'pg_operator'::regclass                                              THEN 'OPERATOR'
                        WHEN pg_depend.classid::regclass = 'pg_opfamily'::regclass                                              THEN 'OPERATOR FAMILY'
                        WHEN pg_depend.classid::regclass = 'pg_opclass'::regclass                                               THEN 'OPERATOR CLASS'
                        WHEN pg_depend.classid::regclass = 'pg_language'::regclass                                              THEN 'LANGUAGE'
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass AND dpndnt_pg_rewrite.rulename = '_RETURN'    THEN 'VIEW'
                        WHEN pg_depend.classid::regclass = 'pg_rewrite'::regclass                                               THEN 'RULE'
                        WHEN pg_depend.classid::regclass = 'pg_trigger'::regclass                                               THEN 'TRIGGER'
                        WHEN pg_depend.classid::regclass = 'pg_namespace'::regclass                                             THEN 'SCHEMA'
                        WHEN pg_depend.classid::regclass = 'pg_ts_config'::regclass                                             THEN 'TEXT SEARCH CONFIG'
                        WHEN pg_depend.classid::regclass = 'pg_ts_dict'::regclass                                               THEN 'TEXT SEARCH DICTIONARY'
                        WHEN pg_depend.classid::regclass = 'pg_ts_parser'::regclass                                             THEN 'TEXT SEARCH PARSER'
                        WHEN pg_depend.classid::regclass = 'pg_ts_template'::regclass                                           THEN 'TEXT SEARCH TEMPLATE'
                        WHEN pg_depend.classid::regclass = 'pg_extension'::regclass                                             THEN 'EXTENSION'
                        WHEN pg_depend.classid::regclass = 'pg_foreign_data_wrapper'::regclass                                  THEN 'FOREIGN DATA WRAPPER'
                        WHEN pg_depend.classid::regclass = 'pg_foreign_server'::regclass                                        THEN 'FOREIGN SERVER'
                        WHEN pg_depend.classid::regclass = 'pg_collation'::regclass                                             THEN 'COLLATION'
                        WHEN pg_depend.classid::regclass = 'pg_cast'::regclass                                                  THEN 'CAST'
                        ELSE 'unknown' END AS dependent_type,
            pg_depend.refobjid,
            CASE    WHEN pg_depend.refclassid::regclass = 'pg_trigger'::regclass                                                THEN dpnder_pg_trigger_proc.oid
                    WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN'     THEN dpnder_pg_rewrite_class.oid
                    ELSE pg_depend.refobjid END AS effective_refobjid,
            CASE        WHEN pg_depend.refclassid::regclass = 'pg_type'::regclass                                               THEN dpnder_pg_namespace_type           .nspname || '.' ||  dpnder_pg_type.                 typname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_roles'::regclass                                              THEN                                                        dpnder_pg_roles.                rolname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_proc'::regclass                                               THEN dpnder_pg_namespace_proc           .nspname || '.' ||  dpnder_pg_proc.                 proname::text || '(' || COALESCE(pg_get_function_arguments(dpnder_pg_proc.oid), '') || ')'
                        WHEN pg_depend.refclassid::regclass = 'pg_class'::regclass                                              THEN dpnder_pg_namespace_class          .nspname || '.' ||  dpnder_pg_class.                relname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_constraint'::regclass                                         THEN dpnder_pg_namespace_constraint     .nspname || '.' ||  dpnder_pg_constraint.           conname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_conversion'::regclass                                         THEN dpnder_pg_namespace_conversion     .nspname || '.' ||  dpnder_pg_conversion.           conname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_operator'::regclass                                           THEN dpnder_pg_namespace_operator       .nspname || '.' ||  dpnder_pg_operator.             oprname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_opfamily'::regclass                                           THEN dpnder_pg_namespace_opfamily       .nspname || '.' ||  dpnder_pg_opfamily.             opfname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_opclass'::regclass                                            THEN dpnder_pg_namespace_opclass        .nspname || '.' ||  dpnder_pg_opclass.              opcname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN' THEN dpnder_pg_namespace_rewrite_class  .nspname || '.' ||  dpnder_pg_rewrite_class.        relname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass                                            THEN                                                        dpnder_pg_rewrite.              rulename::text
                        WHEN pg_depend.refclassid::regclass = 'pg_language'::regclass                                           THEN                                                        dpnder_pg_language.             lanname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_trigger'::regclass                                            THEN dpnder_pg_namespace_trigger_proc   .nspname || '.' ||  dpnder_pg_trigger_proc.         proname::text || '(' || COALESCE(pg_get_function_arguments(dpnder_pg_trigger_proc.oid), '') || ')'
                        WHEN pg_depend.refclassid::regclass = 'pg_namespace'::regclass                                          THEN                                                        dpnder_pg_namespace.            nspname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_config'::regclass                                          THEN dpnder_pg_namespace_ts_config      .nspname || '.' ||  dpnder_pg_ts_config.            cfgname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_dict'::regclass                                            THEN dpnder_pg_namespace_ts_dict        .nspname || '.' ||  dpnder_pg_ts_dict.              dictname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_parser'::regclass                                          THEN dpnder_pg_namespace_ts_parser      .nspname || '.' ||  dpnder_pg_ts_parser.            prsname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_template'::regclass                                        THEN dpnder_pg_namespace_ts_template    .nspname || '.' ||  dpnder_pg_ts_template.          tmplname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_extension'::regclass                                          THEN dpnder_pg_namespace_extension      .nspname || '.' ||  dpnder_pg_extension.            extname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_data_wrapper'::regclass                               THEN                                                        dpnder_pg_foreign_data_wrapper. fdwname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_server'::regclass                                     THEN                                                        dpnder_pg_foreign_server.       srvname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_collation'::regclass                                          THEN dpnder_pg_namespace_collation      .nspname || '.' ||  dpnder_pg_collation.            collname::text
                        WHEN pg_depend.refclassid::regclass = 'pg_cast'::regclass                                               THEN                                                        dpnder_pg_cast.                 oid::text
                        ELSE 'unknown' END AS depender_name,
            CASE        WHEN pg_depend.refclassid::regclass = 'pg_type'::regclass                                               THEN 'TYPE'
                        WHEN pg_depend.refclassid::regclass = 'pg_roles'::regclass                                              THEN 'ROLE'
                        WHEN pg_depend.refclassid::regclass = 'pg_proc'::regclass                                               THEN 'FUNCTION'
                        WHEN pg_depend.refclassid::regclass = 'pg_class'::regclass                                              THEN
                                        	(CASE dpnder_pg_class.relkind   WHEN 'r' THEN 'TABLE'
                                        								    WHEN 'i' THEN 'INDEX'
                                        								    WHEN 'S' THEN 'SEQUENCE'
                                        								    WHEN 'v' THEN 'VIEW'
                                        								    WHEN 'c' THEN 'COMPOSITE TYPE'
                                        								    WHEN 't' THEN 'TOAST TABLE'
                                        								    WHEN 'f' THEN 'FOREIGN TABLE' END)
                        WHEN pg_depend.refclassid::regclass = 'pg_constraint'::regclass                                         THEN 'CONSTRAINT'
                        WHEN pg_depend.refclassid::regclass = 'pg_conversion'::regclass                                         THEN 'CONVERSION'
                        WHEN pg_depend.refclassid::regclass = 'pg_operator'::regclass                                           THEN 'OPERATOR'
                        WHEN pg_depend.refclassid::regclass = 'pg_opfamily'::regclass                                           THEN 'OPERATOR FAMILY'
                        WHEN pg_depend.refclassid::regclass = 'pg_opclass'::regclass                                            THEN 'OPERATOR CLASS'
                        WHEN pg_depend.refclassid::regclass = 'pg_language'::regclass                                           THEN 'LANGUAGE'
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass AND dpnder_pg_rewrite.rulename = '_RETURN' THEN 'VIEW'
                        WHEN pg_depend.refclassid::regclass = 'pg_rewrite'::regclass                                            THEN 'RULE'
                        WHEN pg_depend.refclassid::regclass = 'pg_trigger'::regclass                                            THEN 'TRIGGER'
                        WHEN pg_depend.refclassid::regclass = 'pg_namespace'::regclass                                          THEN 'SCHEMA'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_config'::regclass                                          THEN 'TEXT SEARCH CONFIG'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_dict'::regclass                                            THEN 'TEXT SEARCH DICTIONARY'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_parser'::regclass                                          THEN 'TEXT SEARCH PARSER'
                        WHEN pg_depend.refclassid::regclass = 'pg_ts_template'::regclass                                        THEN 'TEXT SEARCH TEMPLATE'
                        WHEN pg_depend.refclassid::regclass = 'pg_extension'::regclass                                          THEN 'EXTENSION'
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_data_wrapper'::regclass                               THEN 'FOREIGN DATA WRAPPER'
                        WHEN pg_depend.refclassid::regclass = 'pg_foreign_server'::regclass                                     THEN 'FOREIGN SERVER'
                        WHEN pg_depend.refclassid::regclass = 'pg_collation'::regclass                                          THEN 'COLLATION'
                        WHEN pg_depend.refclassid::regclass = 'pg_cast'::regclass                                               THEN 'CAST'
                        ELSE 'unknown' END AS depender_type,
            (CASE   WHEN pg_depend.deptype = 'p'    THEN 'Pinned'
                    WHEN pg_depend.deptype = 'i'    THEN 'Internal'
                    WHEN pg_depend.deptype = 'a'    THEN 'Automatic'
                    WHEN pg_depend.deptype = 'n'    THEN 'Normal'
                    WHEN pg_depend.deptype = 'o_sh' THEN 'Owner'
                    WHEN pg_depend.deptype = 'a_sh' THEN 'ACL'
                    WHEN pg_depend.deptype = 'p_sh' THEN 'Pinned' END)::text AS deptype
        FROM pg_depend
        -- depender
        LEFT JOIN pg_roles                  dpnder_pg_roles                 ON dpnder_pg_roles.oid                  = pg_depend.refobjid::oid
        LEFT JOIN pg_type                   dpnder_pg_type                  ON dpnder_pg_type.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_proc                   dpnder_pg_proc                  ON dpnder_pg_proc.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_class                  dpnder_pg_class                 ON dpnder_pg_class.oid                  = pg_depend.refobjid::oid
        LEFT JOIN pg_attribute              dpnder_pg_attribute             ON dpnder_pg_attribute.attrelid         = pg_depend.refobjid::oid
                                                                           AND dpnder_pg_attribute.attnum           = pg_depend.refobjsubid
        LEFT JOIN pg_constraint             dpnder_pg_constraint            ON dpnder_pg_constraint.oid             = pg_depend.refobjid::oid
        LEFT JOIN pg_conversion             dpnder_pg_conversion            ON dpnder_pg_conversion.oid             = pg_depend.refobjid::oid
        LEFT JOIN pg_operator               dpnder_pg_operator              ON dpnder_pg_operator.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_opfamily               dpnder_pg_opfamily              ON dpnder_pg_opfamily.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_opclass                dpnder_pg_opclass               ON dpnder_pg_opclass.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_language               dpnder_pg_language              ON dpnder_pg_language.oid               = pg_depend.refobjid::oid
        LEFT JOIN pg_rewrite                dpnder_pg_rewrite               ON dpnder_pg_rewrite.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_class                  dpnder_pg_rewrite_class         ON dpnder_pg_rewrite_class.oid          = dpnder_pg_rewrite.ev_class::oid
        LEFT JOIN pg_trigger                dpnder_pg_trigger               ON dpnder_pg_trigger.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace             ON dpnder_pg_namespace.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_config              dpnder_pg_ts_config             ON dpnder_pg_ts_config.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_dict                dpnder_pg_ts_dict               ON dpnder_pg_ts_dict.oid                = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_parser              dpnder_pg_ts_parser             ON dpnder_pg_ts_parser.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_ts_template            dpnder_pg_ts_template           ON dpnder_pg_ts_template.oid            = pg_depend.refobjid::oid
        LEFT JOIN pg_extension              dpnder_pg_extension             ON dpnder_pg_extension.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_foreign_data_wrapper   dpnder_pg_foreign_data_wrapper  ON dpnder_pg_foreign_data_wrapper.oid   = pg_depend.refobjid::oid
        LEFT JOIN pg_foreign_server         dpnder_pg_foreign_server        ON dpnder_pg_foreign_server.oid         = pg_depend.refobjid::oid
        LEFT JOIN pg_collation              dpnder_pg_collation             ON dpnder_pg_collation.oid              = pg_depend.refobjid::oid
        LEFT JOIN pg_cast                   dpnder_pg_cast                  ON dpnder_pg_cast.oid                   = pg_depend.refobjid::oid
        LEFT JOIN pg_proc                   dpnder_pg_trigger_proc                    ON dpnder_pg_trigger_proc.oid                     = dpnder_pg_trigger.tgfoid
        LEFT JOIN pg_type                   dpnder_pg_proc_type                       ON dpnder_pg_proc_type.oid                        = dpnder_pg_proc.prorettype
        LEFT JOIN pg_namespace              dpnder_pg_namespace_type                  ON dpnder_pg_namespace_type.oid                   = dpnder_pg_type.                    typnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_proc                  ON dpnder_pg_namespace_proc.oid                   = dpnder_pg_proc.                    pronamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_class                 ON dpnder_pg_namespace_class.oid                  = dpnder_pg_class.                   relnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_constraint            ON dpnder_pg_namespace_constraint.oid             = dpnder_pg_constraint.              connamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_conversion            ON dpnder_pg_namespace_conversion.oid             = dpnder_pg_conversion.              connamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_operator              ON dpnder_pg_namespace_operator.oid               = dpnder_pg_operator.                oprnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_opfamily              ON dpnder_pg_namespace_opfamily.oid               = dpnder_pg_opfamily.                opfnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_opclass               ON dpnder_pg_namespace_opclass.oid                = dpnder_pg_opclass.                 opcnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_rewrite_class         ON dpnder_pg_namespace_rewrite_class.oid          = dpnder_pg_rewrite_class.           relnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_config             ON dpnder_pg_namespace_ts_config.oid              = dpnder_pg_ts_config.               cfgnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_dict               ON dpnder_pg_namespace_ts_dict.oid                = dpnder_pg_ts_dict.                 dictnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_parser             ON dpnder_pg_namespace_ts_parser.oid              = dpnder_pg_ts_parser.               prsnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_ts_template           ON dpnder_pg_namespace_ts_template.oid            = dpnder_pg_ts_template.             tmplnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_extension             ON dpnder_pg_namespace_extension.oid              = dpnder_pg_extension.               extnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_collation             ON dpnder_pg_namespace_collation.oid              = dpnder_pg_collation.               collnamespace::oid
        LEFT JOIN pg_namespace              dpnder_pg_namespace_trigger_proc          ON dpnder_pg_namespace_trigger_proc.oid           = dpnder_pg_trigger_proc.            pronamespace::oid
        -- dependents
        LEFT JOIN pg_roles                  dpndnt_pg_roles                 ON dpndnt_pg_roles.oid                  = pg_depend.objid::oid
        LEFT JOIN pg_type                   dpndnt_pg_type                  ON dpndnt_pg_type.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_proc                   dpndnt_pg_proc                  ON dpndnt_pg_proc.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_class                  dpndnt_pg_class                 ON dpndnt_pg_class.oid                  = pg_depend.objid::oid
        LEFT JOIN pg_attribute              dpndnt_pg_attribute             ON dpndnt_pg_attribute.attrelid         = pg_depend.objid::oid
                                                                           AND dpndnt_pg_attribute.attnum           = pg_depend.objsubid
        LEFT JOIN pg_constraint             dpndnt_pg_constraint            ON dpndnt_pg_constraint.oid             = pg_depend.objid::oid
        LEFT JOIN pg_conversion             dpndnt_pg_conversion            ON dpndnt_pg_conversion.oid             = pg_depend.objid::oid
        LEFT JOIN pg_operator               dpndnt_pg_operator              ON dpndnt_pg_operator.oid               = pg_depend.objid::oid
        LEFT JOIN pg_opfamily               dpndnt_pg_opfamily              ON dpndnt_pg_opfamily.oid               = pg_depend.objid::oid
        LEFT JOIN pg_opclass                dpndnt_pg_opclass               ON dpndnt_pg_opclass.oid                = pg_depend.objid::oid
        LEFT JOIN pg_language               dpndnt_pg_language              ON dpndnt_pg_language.oid               = pg_depend.objid::oid
        LEFT JOIN pg_rewrite                dpndnt_pg_rewrite               ON dpndnt_pg_rewrite.oid                = pg_depend.objid::oid
        LEFT JOIN pg_class                  dpndnt_pg_rewrite_class         ON dpndnt_pg_rewrite_class.oid          = dpndnt_pg_rewrite.ev_class::oid
        LEFT JOIN pg_trigger                dpndnt_pg_trigger               ON dpndnt_pg_trigger.oid                = pg_depend.objid::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace             ON dpndnt_pg_namespace.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_config              dpndnt_pg_ts_config             ON dpndnt_pg_ts_config.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_dict                dpndnt_pg_ts_dict               ON dpndnt_pg_ts_dict.oid                = pg_depend.objid::oid
        LEFT JOIN pg_ts_parser              dpndnt_pg_ts_parser             ON dpndnt_pg_ts_parser.oid              = pg_depend.objid::oid
        LEFT JOIN pg_ts_template            dpndnt_pg_ts_template           ON dpndnt_pg_ts_template.oid            = pg_depend.objid::oid
        LEFT JOIN pg_extension              dpndnt_pg_extension             ON dpndnt_pg_extension.oid              = pg_depend.objid::oid
        LEFT JOIN pg_foreign_data_wrapper   dpndnt_pg_foreign_data_wrapper  ON dpndnt_pg_foreign_data_wrapper.oid   = pg_depend.objid::oid
        LEFT JOIN pg_foreign_server         dpndnt_pg_foreign_server        ON dpndnt_pg_foreign_server.oid         = pg_depend.objid::oid
        LEFT JOIN pg_collation              dpndnt_pg_collation             ON dpndnt_pg_collation.oid              = pg_depend.objid::oid
        LEFT JOIN pg_cast                   dpndnt_pg_cast                  ON dpndnt_pg_cast.oid                   = pg_depend.objid::oid
        LEFT JOIN pg_proc                   dpndnt_pg_trigger_proc                    ON dpndnt_pg_trigger_proc.oid                     = dpndnt_pg_trigger.tgfoid
        LEFT JOIN pg_type                   dpndnt_pg_proc_type                       ON dpndnt_pg_proc_type.oid                        = dpndnt_pg_proc.prorettype
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_type                  ON dpndnt_pg_namespace_type.oid                   = dpndnt_pg_type.                    typnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_proc                  ON dpndnt_pg_namespace_proc.oid                   = dpndnt_pg_proc.                    pronamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_class                 ON dpndnt_pg_namespace_class.oid                  = dpndnt_pg_class.                   relnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_constraint            ON dpndnt_pg_namespace_constraint.oid             = dpndnt_pg_constraint.              connamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_conversion            ON dpndnt_pg_namespace_conversion.oid             = dpndnt_pg_conversion.              connamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_operator              ON dpndnt_pg_namespace_operator.oid               = dpndnt_pg_operator.                oprnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_opfamily              ON dpndnt_pg_namespace_opfamily.oid               = dpndnt_pg_opfamily.                opfnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_opclass               ON dpndnt_pg_namespace_opclass.oid                = dpndnt_pg_opclass.                 opcnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_rewrite_class         ON dpndnt_pg_namespace_rewrite_class.oid          = dpndnt_pg_rewrite_class.           relnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_config             ON dpndnt_pg_namespace_ts_config.oid              = dpndnt_pg_ts_config.               cfgnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_dict               ON dpndnt_pg_namespace_ts_dict.oid                = dpndnt_pg_ts_dict.                 dictnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_parser             ON dpndnt_pg_namespace_ts_parser.oid              = dpndnt_pg_ts_parser.               prsnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_ts_template           ON dpndnt_pg_namespace_ts_template.oid            = dpndnt_pg_ts_template.             tmplnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_extension             ON dpndnt_pg_namespace_extension.oid              = dpndnt_pg_extension.               extnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_collation             ON dpndnt_pg_namespace_collation.oid              = dpndnt_pg_collation.               collnamespace::oid
        LEFT JOIN pg_namespace              dpndnt_pg_namespace_trigger_proc          ON dpndnt_pg_namespace_trigger_proc.oid           = dpndnt_pg_trigger_proc.            pronamespace::oid
        --recurse
        JOIN dep_recursive dep_recursive ON dep_recursive.refobjid::oid = pg_depend.objid::oid
        WHERE pg_depend.objid != 0
          AND pg_depend.refobjid != 0
          AND pg_depend.deptype != 'i'
          AND pg_depend.classid::regclass != 'pg_default_acl'::regclass
          AND pg_depend.classid::regclass != 'pg_attrdef'::regclass
          AND (dpndnt_pg_proc_type.typname != 'trigger' OR dpndnt_pg_proc_type.typname IS NULL)
          AND (dpnder_pg_proc_type.typname != 'trigger' OR dpnder_pg_proc_type.typname IS NULL)
          AND pg_depend.refobjid != '{{INTOID}}'::oid
)
SELECT *
    FROM dep_recursive
    WHERE depender_name <> '' AND {{WHERE}}
            */});
            
            GS.envSocket = GS.openSocket('env');
            
            function rescale() {
                svg.attr('transform', d3.event.transform.toString());
            }
            
            window.addEventListener('mouseup', function () {
                mousedown_node = -1;
            });
            
            window.addEventListener('mousedown', function () {
                if (mousedown_node !== -1) {
                    d3.select('#inspector_body > svg > g').call(d3.zoom().on('zoom', rescale));
                }
            });
            
            function node_click(d) {
                if (d3.event.defaultPrevented) return;
                
                d3.event.stopPropagation();
                
                var i, len;
                for (i = 0, len = graph.nodes.length; i < len; i += 1) {
                    var node = document.getElementById('node' + i);
                    node.classList.remove('selected');
                }
                
                var depType = GS.qryGetVal(GS.getQueryString(), 'dep-type');
                if (depType !== 'dependencies' && depType !== 'dependents') {
                    depType = 'dependents';
                }
                
                for (i = 0, len = graph.nodes.length; i < len; i += 1) {
                    if (graph.nodes[i] === d) {
                        var node = document.getElementById('node' + i);
                        node.classList.add('selected');
                    }
                }
                
                var i, len, html = '', objectType = '';
                html += '<div id="properties-container" style="min-height: 2em; overflow: auto;"></div><br />';
                html += '<label for="dependencies-container">Dependencies:</label>';
                html += '<div id="dependencies-container" style="min-height: 2em; overflow: auto;"></div><br />';
                html += '<label for="dependents-container">Dependents:</label>';
                html += '<div id="dependents-container" style="min-height: 2em; overflow: auto;"></div>';
                
                document.getElementById('obj_properties').innerHTML = html;
                
                _width = inspector_body.clientWidth;
                _height = inspector_body.clientHeight;
                d3.select('svg')
                    .attr('width', _width)
                    .attr('height', _height);
                
                objectType = d.group.toLowerCase().replace(/[ ][a-z]/gi, function (match) {
                    return match[1].toUpperCase();
                }).replace('textSearch', 'ts')
                  .replace('foreignDataWrapper', 'fdw')
                  .replace('foreignServer', 'fdw_server')
                  .replace('toastTable', 'table')
                  .replace('foreignTable', 'table')
                  .replace('compositeType', 'type')
                  .replace('trigger', 'function');
                
                
                getListData(propQuery['prop_' + objectType].replace(/\{\{INTOID\}\}/g, d.oid)
                                                           .replace(/\{\{STRSQLSAFENAME\}\}/g, d.name),
                            document.getElementById('properties-container'),
                            function (arrRecords) {
                    var i, len, col_i, col_len, strHTML = '';
                    
                    for (col_i = 1, col_len = arrRecords[0].length; col_i < col_len; col_i += 1) {
                        strHTML +=  '<tr>' +
                                        '<th>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[1][col_i])) + '</th>' +
                                        '<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[2][col_i])) + '</td>' +
                                    '</tr>';
                    }
                    
                    document.getElementById('properties-container').innerHTML =
                        '<table class="table-stats">' + strHTML + '</table>';
                    
                    _width = inspector_body.clientWidth;
                    _height = inspector_body.clientHeight;
                    d3.select('svg')
                        .attr('width', _width)
                        .attr('height', _height);
                });
                getListData(infoQuery.dependencies.replace(/\{\{INTOID\}\}/g, d.oid),
                            document.getElementById('dependencies-container'),
                            function (arrRecords) {
                    var i, len, strHTML = '';
                    
                    for (i = 1, len = arrRecords.length; i < len; i += 1) {
                        strHTML +=  '<tr>' +
                                        '<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[i][3])) + '</td>' +
                                        '<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[i][4])) + '</td>' +
                                        '<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[i][6])) + '</td>' +
                                        //'<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[i][5])) + '</td>' +
                                    '</tr>';
                    }
                    
                    document.getElementById('dependencies-container').innerHTML =
                        '<table class="table-dep">' +
                            '<thead>' +
                                '<tr>' +
                                    '<th>Object Type</th>' +
                                    '<th>Object Name</th>' +
                                    '<th>Dependence Type</th>' +
                                    //'<th>OID</th>' +
                                '</tr>' +
                            '</thead>' +
                            strHTML +
                        '</table>';
                    
                    _width = document.body.clientWidth;
                    _height = inspector_body.clientHeight;
                    d3.select('svg')
                        .attr('width', _width)
                        .attr('height', _height);
                });
                getListData(infoQuery.dependents.replace(/\{\{INTOID\}\}/g, d.oid),
                            document.getElementById('dependents-container'),
                            function (arrRecords) {
                    var i, len, strHTML = '';
                    
                    for (i = 1, len = arrRecords.length; i < len; i += 1) {
                        strHTML +=  '<tr>' +
                                        '<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[i][0])) + '</td>' +
                                        '<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[i][1])) + '</td>' +
                                        '<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[i][6])) + '</td>' +
                                        //'<td>' + encodeHTML(GS.decodeFromTabDelimited(arrRecords[i][2])) + '</td>' +
                                    '</tr>';
                    }
                    
                    document.getElementById('dependents-container').innerHTML =
                        '<table class="table-dep">' +
                            '<thead>' +
                                '<tr>' +
                                    '<th>Object Type</th>' +
                                    '<th>Object Name</th>' +
                                    '<th>Dependence Type</th>' +
                                    //'<th>OID</th>' +
                                '</tr>' +
                            '</thead>' +
                            strHTML +
                        '</table>';
                    
                    _width = inspector_body.clientWidth;
                    _height = inspector_body.clientHeight;
                    d3.select('svg')
                        .attr('width', _width)
                        .attr('height', _height);
                });
            }
            
            window.addEventListener('click', function (event) {
                if (event.target.getAttribute('id') === 'refresh_view') {
                    GS.triggerEvent(window, 'load_data');
                    
                    /*_width = inspector_body.clientWidth;
                    _height = inspector_body.clientHeight;
                    force
                        .force('x', d3.forceX(_width / 2).strength(0.2))
                        .force('y', d3.forceY(_height / 2).strength(0.2));
                    d3.select('svg')
                        .attr('width', _width)
                        .attr('height', _height);*/
                } else if ( event.target.tagName.toUpperCase() === 'SVG' ||
                            event.target.tagName.toUpperCase() === 'RECT') {
                    for (i = 0, len = graph.nodes.length; i < len; i += 1) {
                        var node = document.getElementById('node' + i);
                        node.classList.remove('selected');
                    }
                    document.getElementById('obj_properties').innerHTML = '';
                    
                    _width = inspector_body.clientWidth;
                    _height = inspector_body.clientHeight;
                    force
                        .force('x', d3.forceX(_width / 2).strength(0.2))
                        .force('y', d3.forceY(_height / 2).strength(0.2));
                    d3.select('svg')
                        .attr('width', _width)
                        .attr('height', _height);
                }
            });
            
            // The load event is used for other things as well,
            // so this serves as a buffer to prevent those things
            // from happening when we press the refresh button
            window.addEventListener('load', function () {
                GS.triggerEvent(window, 'load_data');
                
                color = d3.scaleOrdinal()
                    .domain([])
                    .range(d3.scaleOrdinal(d3.schemeCategory20).range().concat(d3.scaleOrdinal(d3.schemeCategory20C).range()));
                color('TYPE'                    );
                color('ROLE'                    );
                color('FUNCTION'                );
                color('TABLE'                   );
                color('INDEX'                   );
                color('SEQUENCE'                );
                color('VIEW'                    );
                color('COMPOSITE TYPE'          );
                color('TOAST TABLE'             );
                color('FOREIGN TABLE'           );
                color('CONSTRAINT'              );
                color('CONVERSION'              );
                color('OPERATOR'                );
                color('OPERATOR FAMILY'         );
                color('OPERATOR CLASS'          );
                color('LANGUAGE'                );
                color('RULE'                    );
                color('TRIGGER'                 );
                color('SCHEMA'                  );
                color('TEXT SEARCH CONFIG'      );
                color('TEXT SEARCH DICTIONARY'  );
                color('TEXT SEARCH PARSER'      );
                color('TEXT SEARCH TEMPLATE'    );
                color('EXTENSION'               );
                color('FOREIGN DATA WRAPPER'    );
                color('FOREIGN SERVER'          );
                color('COLLATION'               );
                color('CAST'                    );
                color('TABLESPACE'              );
            });
            
            window.addEventListener('resize', function () {
                _width = inspector_body.clientWidth;
                _height = inspector_body.clientHeight;
                document.getElementById('obj_properties').innerHTML = '';
                if (force !== null) {
                    force
                        .force('x', d3.forceX(_width / 2).strength(0.2))
                        .force('y', d3.forceY(_height / 2).strength(0.2));
                }
                d3.select('svg')
                    .attr('width', _width)
                    .attr('height', _height);
            });
            
            window.addEventListener('load_data', function () {
                inspector_body = document.querySelector('#inspector_body');
                
                _width = inspector_body.clientWidth;
                _height = inspector_body.clientHeight;
                
                var depType = GS.qryGetVal(GS.getQueryString(), 'dep-type');
                if (depType !== 'dependencies' && depType !== 'dependents') {
                    depType = 'dependents';
                }
                document.getElementById('dep_type').value = depType;
                document.getElementById('dep_type').addEventListener('change', function () {
                    GS.pushQueryString('oid=' + GS.qryGetVal(GS.getQueryString(), 'oid') + '&dep-type=' + this.value);
                    window.location.reload();
                });
                
                depData = '';
                
                document.title = depType + ' Viewer';
                document.title = document.title.replace(/^d/, 'D');
                document.getElementById('inspector_header').innerText = document.title;
                GS.addLoader('dep-data-loader', 'Loading...');
                GS.requestFromSocket(GS.envSocket, 'RAW\n' +
                            scripts[depType]
                                .replace(/\{\{INTOID\}\}/g, GS.qryGetVal(GS.getQueryString(), 'oid'))
                                // I put the function here because if I just passed the where clause as a string, it would collapse "$$" to "$"
                                // I got this solution from http://stackoverflow.com/a/28103073/4548445
                                .replace(/\{\{WHERE\}\}/g, function () { return where_clause }),
                        function (data, error, errorData) {
                    if (!error) {
                        if (data.substring(0, 5) !== 'QUERY' &&
                            data.substring(0, 5) !== 'START' &&
                            data.substring(0, 3) !== 'END' &&
                            data.substring(0, 4) !== 'ROWS' &&
                            data.substring(0, 7) !== 'COLUMNS' &&
                            data !== '\\.' &&
                            data !== 'TRANSACTION COMPLETED') {
                            
                            depData += (depData !== '' ? '\n' : '') + data;
                        } else if (data === 'TRANSACTION COMPLETED') {
                            GS.removeLoader('dep-data-loader');
                            GS.triggerEvent(window, 'show_data');
                        }
                    } else {
                        GS.removeLoader('dep-data-loader');
                        GS.webSocketErrorDialog(errorData);
                    }
                });
            });
            
            function show_hide(type, value) {
                hidingOptions[type] = value;
                
                link.remove();
                node.remove();
                node_text.remove();
                
                GS.triggerEvent(window, 'show_data');
            }
            function search(search_term) {
                where_clause = GS.searchToWhere('dependent_name', search_term);
                GS.triggerEvent(window, 'load_data');
            }
            
            function dragstarted(d) {
                if (!d3.event.active) force.alphaTarget(0.3).restart();
                d.fx = d.x;
                d.fy = d.y;
            }
            
            function dragged(d) {
                d.fx = d3.event.x;
                d.fy = d3.event.y;
            }
            
            function dragended(d) {
                if (!d3.event.active) force.alphaTarget(0);
                d.fx = null;
                d.fy = null;
            }
            
            window.addEventListener('show_data', function () {
                'use strict';
                
                arrLine = depData.split('\n');
                
                if (depData === '') {
                    document.getElementById('inspector_body').innerHTML = '<p id="no-deps">Nothing to show</p>';
                    return;
                }
                
                if (force !== null) {
                    force.on('tick', null);
                }
                document.getElementById('inspector_body').innerHTML = '';
                
                svg = d3.select('#inspector_body')
                  .append('svg')
                    .attr('width', _width)
                    .attr('height', _height)
                  .append('g')
                    .attr('class', 'zoom')
                    .call(d3.zoom().on('zoom', rescale))
                  .append('g');
                
                svg.append('defs').selectAll('marker')
                    .data([{'type': 'end'}])    // Different link/path types can be defined here
                  .enter().append('svg:marker') // This section adds in the arrows
                    .attr('id', function (d) { return d.type; })
                    .attr('viewBox', "0 0 10 10")
                    .attr('refX', 1)
                    .attr('refY', 5)
                    .attr('markerWidth', 6)
                    .attr('markerHeight', 6)
                    .attr('orient', 'auto')
                  .append('path')
                    .attr('d', 'M 0 0 L 10 5 L 0 10 z');
                
                svg.attr('transform',
                    'translate(' + trans + ') ' +
                    'scale(' + scale + ')');
                
                svg.append('rect')
                    .attr('width', _width)
                    .attr('height', _height);
                
                var oldNodes = graph.nodes.splice(0, graph.nodes.length);
                graph.links.length = 0;
                
                var depType = GS.qryGetVal(GS.getQueryString(), 'dep-type');
                if (depType !== 'dependencies' && depType !== 'dependents') {
                    depType = 'dependents';
                }
                
                // The reason for swiching the column names if it is a dependency search,
                //   is so that we don't have to have an even bigger if down below, where we push to the node array
                if (depType === 'dependencies') {
                    arrColumn = ['refobjid', 'effective_refobjid', 'depender_name', 'depender_type', 'objid', 'effective_objid', 'dependent_name', 'dependent_type', 'deptype'];
                } else {
                    arrColumn = ['objid', 'effective_objid', 'dependent_name', 'dependent_type', 'refobjid', 'effective_refobjid', 'depender_name', 'depender_type', 'deptype'];
                }
                
                arrLine.forEach(function (cur, i) {
                    arrLine[i] = arrLine[i].split('\t');
                    arrLine[i].forEach(function (cur, j) {
                        arrLine[i][arrColumn[j]] = GS.decodeFromTabDelimited(arrLine[i][j]);
                    });
                });
                
                var skippedNodes = 0;
                
                var rand = function () {
                    return parseInt(('' + Math.random()).substring(2), 10);
                };
                
                arrLine.forEach(function (cur, i) {
                    var nodeIsAlreadyThere = false, j, len,
                        oldNode = {
                            x:  (rand() % _width),
                            y:  (rand() % _height)
                        };
                    oldNode.px = oldNode.x + ((rand() % 20) - 10);
                    oldNode.py = oldNode.y + ((rand() % 20) - 10);
                    
                    if (hidingOptions[arrLine[i].dependent_type] === undefined) {
                        hidingOptions[arrLine[i].dependent_type] = '-1';
                    }
                    if (hidingOptions[arrLine[i].dependent_type] === '-1') {
                        for (j = 0, len = graph.nodes.length; j < len; j += 1) {
                            if (graph.nodes[j].oid === arrLine[i].effective_objid) {
                                nodeIsAlreadyThere = true;
                                break;
                            }
                        }
                        for (j = 0, len = oldNodes.length; j < len; j += 1) {
                            if (oldNodes[j].oid === arrLine[i].effective_objid) {
                                oldNode = oldNodes[j];
                                break;
                            }
                        }
                        if (nodeIsAlreadyThere === false && arrLine[i].effective_objid) {
                            graph.nodes.push({
                                oid  : arrLine[i].effective_objid,
                                name : arrLine[i].dependent_name,
                                group: arrLine[i].dependent_type,
                                x: oldNode.x,
                                y: oldNode.y,
                                px: oldNode.px,
                                py: oldNode.py
                            });
                        }
                    }
                });
                
                arrLine.forEach(function (cur, i) {
                    var linkSource = -1, linkTarget = -1, nodeIsAlreadyThere = false, j, len;
                    for (j = 0, len = graph.nodes.length; j < len; j += 1) {
                        if (graph.nodes[j].oid === arrLine[i].effective_objid) {
                            linkSource = j;
                        } else if (graph.nodes[j].oid === arrLine[i].effective_refobjid) {
                            linkTarget = j;
                        }
                    }
                    if (linkSource !== -1 && linkTarget !== -1) {
                        if (depType === 'dependents') {
                            var t = linkSource;
                            linkSource = linkTarget;
                            linkTarget = t;
                        }
                        graph.links.push({
                            source: linkSource,
                            target: linkTarget,
                            type  : arrLine[i].deptype
                        });
                    }
                });
                
                var arrTypes = Object.keys(hidingOptions)/*.sort()*/, i, len, optionHTML = '';
                optionHTML += '<gs-text id="search_nodes" placeholder="Search..." remove-bottom onchange="search((search_value = this.value))" value="' + search_value + '"></gs-text>';
                for (i = 0, len = arrTypes.length; i < len; i += 1) {
                    var curType = arrTypes[i].toLowerCase().replace(/ /g, '_');
                    optionHTML += ' <div flex-horizontal>';
                    optionHTML += '     <gs-checkbox id="hide_' + curType +
                                                    '" value="' + hidingOptions[arrTypes[i]] +
                                                    '" inline remove-right remove-top' +
                                                                (i != (len - 1) ? ' remove-bottom' : '') +
                                                    ' onchange="show_hide(\'' + arrTypes[i] + '\', this.value)" ' +
                                                    'style="background: ' + color(arrTypes[i]) +
                                                    '; color: #000000; border: none; box-shadow: none;"></gs-checkbox>';
                    optionHTML += '     <gs-button flex for="hide_' + curType +
                                                    '" remove-left remove-top' +
                                                                (i != (len - 1) ? ' remove-bottom' : '') +
                                                    ' onclick="GS.triggerEvent(document.getElementById(\'hide_' + curType + '\'), \'click\')" ' +
                                                    'style="background: ' + color(arrTypes[i]) +
                                                    '; color: #000000; border: none; box-shadow: none;">' + arrTypes[i] + '</gs-button>';
                    optionHTML += ' </div>';
                }
                document.getElementById('inspector_options').innerHTML = optionHTML;
                document.getElementById('search_nodes').focus();
                
                if (force === null) {
                    force = d3.forceSimulation()
                        .nodes(graph.nodes)
                        .force("charge", d3.forceManyBody()
                            .strength(function () {
                                return -300;
                            })
                        )
                        .force("link", d3.forceLink(graph.links)
                            .distance(function (d) {
                                return d.source.group === d.target.group ? 30 : 100;
                            })//100)
                        )
                        .force('collide', d3.forceCollide().radius(radius))
                        .force('x', d3.forceX(_width / 2).strength(0.2))
                        .force('y', d3.forceY(_height / 2).strength(0.2));
                } else {
                    force
                        .nodes(graph.nodes)
                        .force("link", d3.forceLink(graph.links)
                            .distance(function (d) {
                                return d.source.group === d.target.group ? 30 : 100;
                            })//100)
                        ).restart();
                }
                
                link = svg.selectAll('.link')
                    .data(graph.links)
                  .enter().append('line')
                    .attr('id', function (d) { return 'link' + d.source.index + '_' + d.target.index; })
                    .attr('class', 'link')
                    .attr('marker-end', 'url(#end)')
                    .style('stroke', function (d) { return color(d.target.group); });
                
                node = svg.selectAll('.node')
                    .data(graph.nodes)
                  .enter().append('circle')
                    .attr('id', function (d) { return 'node' + d.index; })
                    .attr('class', 'node')
                    .attr('r', radius)
                    .style('fill', function (d) { return color(d.group); })
                    .on('click', node_click)
                    .call(d3.drag()
                        .on("start", dragstarted)
                        .on("drag", dragged)
                        .on("end", dragended)
                    );
                
                node_text = svg.selectAll('.node_text')
                    .data(graph.nodes)
                  .enter().append('text')
                    .style('fill', '#000000')
                    .style('font-size', '0.75em')
                    .style('font-family', '"Lucida Console", Monaco, monospace')
                    .on('click', node_click)
                    .text(function (d) {
                        d.groupAbbr =
                                d.group === 'TYPE'                      ? 'TYP' :
                                d.group === 'ROLE'                      ? 'R'   :
                                d.group === 'FUNCTION'                  ? 'F'   :
                                d.group === 'TABLE'                     ? 'T'   :
                                d.group === 'INDEX'                     ? 'I'   :
                                d.group === 'SEQUENCE'                  ? 'SEQ' :
                                d.group === 'VIEW'                      ? 'V'   :
                                d.group === 'COMPOSITE TYPE'            ? 'CTP' :
                                d.group === 'TOAST TABLE'               ? 'TT'  :
                                d.group === 'FOREIGN TABLE'             ? 'FT'  :
                                d.group === 'CONSTRAINT'                ? 'C'   :
                                d.group === 'CONVERSION'                ? 'CNV' :
                                d.group === 'OPERATOR'                  ? 'O'   :
                                d.group === 'OPERATOR FAMILY'           ? 'OF'  :
                                d.group === 'OPERATOR CLASS'            ? 'OC'  :
                                d.group === 'LANGUAGE'                  ? 'L'   :
                                d.group === 'RULE'                      ? 'R'  :
                                d.group === 'TRIGGER'                   ? 'TR'  :
                                d.group === 'SCHEMA'                    ? 'S'   :
                                d.group === 'TEXT SEARCH CONFIG'        ? 'TSC' :
                                d.group === 'TEXT SEARCH DICTIONARY'    ? 'TSD' :
                                d.group === 'TEXT SEARCH PARSER'        ? 'TSP' :
                                d.group === 'TEXT SEARCH TEMPLATE'      ? 'TST' :
                                d.group === 'EXTENSION'                 ? 'E'   :
                                d.group === 'FOREIGN DATA WRAPPER'      ? 'FDW' :
                                d.group === 'FOREIGN SERVER'            ? 'SRV' :
                                d.group === 'COLLATION'                 ? 'COL' :
                                d.group === 'CAST'                      ? 'CST' :
                                d.group === 'TABLESPACE'                ? 'SPC' : '';
                        return d.groupAbbr;
                    })
                    .call(d3.drag()
                        .on("start", dragstarted)
                        .on("drag", dragged)
                        .on("end", dragended)
                    );
                
                node.append('title')
                    .text(function (d) { return d.name; });
                node_text.append('title')
                    .text(function (d) { return d.name; });
                
                force.on('tick', function (e) {
                    link.attr('x1', function (d) { return d.target.x; })
                        .attr('y1', function (d) { return d.target.y; })
                        .attr('x2', function (d) { return d.source.x + ((Math.cos(Math.atan2((d.target.y - d.source.y), (d.target.x - d.source.x))) * (radius + 5))); })
                        .attr('y2', function (d) { return d.source.y + ((Math.sin(Math.atan2((d.target.y - d.source.y), (d.target.x - d.source.x))) * (radius + 5))); });
                    
                    node.attr('cx', function (d) { return d.x; })
                        .attr('cy', function (d) { return d.y; });
                    
                    node_text.attr('x', function (d) { return d.x -
                                                            (
                                                                d.groupAbbr.length === 3 ? 9.75 :
                                                                d.groupAbbr.length === 2 ? 6 : 3); })
                             .attr('y', function (d) { return d.y + 3.75; });
                });
            });
        </script>
        
        <style>
            body, gs-body, svg {
                padding: 0;
                margin: 0;
            }
            
            p {
                padding: 0.5em;
                -webkit-box-sizing: border-box;
                   -moz-box-sizing: border-box;
                    -ms-box-sizing: border-box;
                     -o-box-sizing: border-box;
                        box-sizing: border-box;
            }
            
            gs-header {
                overflow: auto;
                -webkit-box-sizing: border-box;
                   -moz-box-sizing: border-box;
                    -ms-box-sizing: border-box;
                     -o-box-sizing: border-box;
                        box-sizing: border-box;
            }
            
            gs-body {
                position: relative;
            }
            
            svg {
                position: absolute;
            }
            
            .node.selected {
                stroke: #C57400;
                stroke-width: 2px;
            }
            
            .link {
                stroke-width: 1px;
            }
            
            #no-deps {
                font-weight: bold;
                font-size: 4em;
                text-align: center;
                margin-top: 2em;
            }
            
            gs-body {
                position: relative;
            }
            
            #inspector_body {
                position: absolute;
                top: 0;
                left: 0;
                bottom: 0;
                right: 0;
            }
            
            #inspector_options {
                position: absolute;
                top: 0;
                right: 0;
                width: 17em;
                height: auto;
                max-height: 45em;
                overflow: auto;
                font-family: "Lucida Console", Monaco, monospace;
            }
            
            #dep_type {
                background: #ffffff;
                color: #000000;
            }
            
            gs-button[icononly] {
                background: none;
            }
            
            gs-button[icononly]:after {
                color: #ffffff;
            }
            
            gs-button[icononly]:hover {
                background: #ffffff;
            }
            
            gs-button[icononly]:hover:after {
                color: #000000;
            }
            
            gs-body {
                background: #ededed;
            }
            
            svg rect {
                fill: #ededed;
            }
            
        </style>
        <script src="../../js/settings.js" type="text/javascript"></script>
        <script>
            if (window.parent) {
                window.parent.addEventListener('resize', function () {
                    if (localStorage && localStorage.customCSS) {
                        refreshCustomCSS(localStorage.customCSS);
                    }
                });
            }
        </script>
        <style id="customCss"></style>
    </head>
    <body>
        <gs-panel id="panel" refresh-on-querystring-values="panel.panel-right">
            <gs-page>
                <gs-header flex-horizontal>
                    <div flex id="inspector_header">Dependent Viewer</div>
                    <gs-select id="dep_type" style="width: 10em;">
                        <option value="dependents">Dependents</option>
                        <option value="dependencies">Dependencies</option>
                    </gs-select>
                    <gs-button id="refresh_view" icon="refresh" icononly mini></gs-button>
                    <gs-button onclick="GS.pushQueryString('panel.panel-right=show');" icon="arrow-left" icononly mini hide-on-desktop></gs-button>
                </gs-header>
                <gs-body>
                    <div id="inspector_body"></div>
                    <div id="inspector_options"></div>
                </gs-body>
            </gs-page>
            <gs-page id="right-bar" style="width: 25em;">
                <gs-header flex-horizontal>
                    <div flex>Object Properties</div>
                    <!-- this button is so that the header is the right height -->
                    <gs-button style="visibility: none;" mini></gs-button>
                </gs-header>
                <gs-body id="obj_properties">
                    
                </gs-body>
            </gs-page>
        </gs-panel>
    </body>
</html>